Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to describe response object in swagger, using yaml?

We have following json response for /papers/15

{
  "data": [
    {
        "id": 1,
        "title": "foo"
    },
    {
        "id": 2,
        "title": "bar"
    }
  ],
  "meta": {
    "total": 15
  }
}

Does anyone know how to describe it swagger yaml file?

like image 443
Sergey Yarotskiy Avatar asked Mar 16 '23 22:03

Sergey Yarotskiy


1 Answers

Ok, I just figured out how to do this, in case somebody will need id. Beside dedicated model definitions section ("definitions") it is possible to do inline model descriptions. Code above will looks like:

responses:
    "200":
      description: Matched Objects
      schema:
        type: object
        properties:
          data:
            type: object
            properties:
              authors:
                type: array
                items:
                  $ref: "#/definitions/object_with_id_and_title"
like image 149
Sergey Yarotskiy Avatar answered Mar 23 '23 10:03

Sergey Yarotskiy