Skip to content

Return values are not shown in Swagger-UI #179

Open
@houmie

Description

@houmie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions