Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return values are not shown in Swagger-UI #179

Open
houmie opened this issue Mar 5, 2020 · 2 comments
Open

Return values are not shown in Swagger-UI #179

houmie opened this issue Mar 5, 2020 · 2 comments

Comments

@houmie
Copy link

houmie commented Mar 5, 2020

Hello all,

I have created a very simple demo to demonstrate that the return values are not shown in swagger-ui:

Screenshot 2020-03-05 at 17 20 39

Requirements.txt:

flask-apispec
flask-marshmallow
flask-restful

Versions:

apispec==3.3.0
Flask==1.1.1
flask-apispec==0.8.6
flask-marshmallow==0.11.0
Flask-RESTful==0.3.8
marshmallow==3.5.0
webargs==5.5.3

Code:

from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from flask import Flask
from flask_apispec import use_kwargs, marshal_with, FlaskApiSpec, MethodResource
from flask_marshmallow import Marshmallow
from flask_restful import Api
from marshmallow import fields

app = Flask(__name__)
api = Api(app)
ma = Marshmallow(app)


class Todo:
    def __init__(self, todo_id, description):
        self.todo_id = todo_id
        self.description = description

    def __getitem__(self, item):
        return getattr(self, item)


class TodoInputSchema(ma.Schema):
    token = fields.Str()


class TodoSchema(ma.Schema):
    class Meta:
        fields = ("todo_id", "description")


class Demo(MethodResource):
    def __init__(self):
        super(Demo, self).__init__()

    @use_kwargs(TodoInputSchema)
    @marshal_with(TodoSchema, code=200)
    def get(self):
        schema = TodoSchema()
        todo = Todo(1, "get Milk")
        return schema.dump(todo)


api.add_resource(Demo, '/')
app.config.update({
    'APISPEC_SPEC': APISpec(
        title='todo',
        version='v1',
        plugins=[MarshmallowPlugin()],
        openapi_version='3.0.2'
    ),
    'APISPEC_SWAGGER_URL': '/swagger/',
})
docs = FlaskApiSpec(app)

docs.register(Demo)

if __name__ == '__main__':
    app.run(debug=True, port=3333)

Run:
http://127.0.0.1:3333/swagger-ui

Why is the return object not shown in Swagger UI?

Many Thanks,
Houman

@playpauseandstop
Copy link

Hi @houmie

I've ran into same issue today, when using openapi_version='3.0.2' in my new project.

The reason is that OpenAPI Schema 3.0 has different responses format comparing to Swagger 2.0, while flask-apispec still produces old response format.

And most interesting, that issue already fixed in #153, but unfortunately that MR is still not merged into the master.

@houmie
Copy link
Author

houmie commented Sep 26, 2020

Hi @sloria,

Why are you not merging #153 ?

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants