4

Given a Flask RESTPlus model like:

todo = api.model("Todo", {
    "id": fields.Integer(example=123),
    "task": fields.String(example="Feed the cat")
})

I want Flask RESTPlus support the Open API response examples property, to export a spec like:

paths:
  /todos/{id}
    get:
      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/Todo'
          examples:
            application/json:
              id: 123
              task: Feed the cat

I have explored the api.doc() & api.response() decorators, but they don't seem to support the response property. E.g.:

    @api.response(200, "OK", todo)
    @api.marshal_with(todo)
    def get(self):
        # . . . 

. . . doesn't populate the response examples property.

Version: flask-restplus==0.13.0

LaSmell
  • 151
  • 8
  • Are you sure ? What version of of Flask-RESTPlus are you using ? I get example section when using `@api.response(200, "OK", todo)`... Go to root path of project, for example `127.0.0.1:5000/`. There should be route with response documented.... – Dinko Pehar Oct 22 '19 at 08:32
  • Using the latest version (0.13.0), the response examples are documented in the Swagger UI, however when you download the swagger json (from /swagger.json endpoint) the JSON doesn't have the examples property in the response section. – LaSmell Oct 23 '19 at 09:16
  • They are documented below, they only use `#/definitions/Todo` permalink. Down below you will see entry for `definitions` and in it will be *Todo* model. – Dinko Pehar Oct 23 '19 at 12:02

0 Answers0