How does one document the returned data for a POST endpoint?

229 Views Asked by At

If I have a simple endpoint like so using flask

import random
class MyResource(Resource):
    def post(self):
        return [i for i in range (random.randrange(100))]

How do I get swagger documentation like so using flask-restplus?

enter image description here

I am looking for some data structure like so

[
    type=integer, description='coin flip',
    ....
]

I can get it to work for the Payload but not for the return/response

1

There are 1 best solutions below

0
Benoît Zu On BEST ANSWER

From https://flask-restplus.readthedocs.io/en/stable/swagger.html

You can optionally specify a response model as the third argument

model = api.model('Model', {
    'name': fields.String,
})

@api.route('/my-resource/')
class MyResource(Resource):
    @api.response(200, 'Success', model)
    def get(self):
        pass