Adding 'Value Example' to swagger, using flask-restx

796 Views Asked by At

how can i add 'value example' (like on picture 3) to swagger documentation (picture 4 is that where i want to put 'value example' in) without using decorator marshall_with/marshall_list_with? Cuz the function got two responses depending on two endpoints enter image description here

enter image description here

enter image description here enter image description here

1

There are 1 best solutions below

0
On

You can use the model to define an example, like this:

...
# define model with example
example_response = api.model('ExampleResponse', {
    'field_you_want': fields.String(example="Example Value")
})


@api.route("/")
class Example(Resource):

    @api.marshal_with(example_response)
    def get(self):
        response = get_response()
        return response, 200
...