如何使用yaml来描述swagger中的响应对象?

Ser*_*kiy 4 api documentation yaml swagger

我们关注/ papers/15的json回复

{
  "data": [
    {
        "id": 1,
        "title": "foo"
    },
    {
        "id": 2,
        "title": "bar"
    }
  ],
  "meta": {
    "total": 15
  }
}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何描述它swagger yaml文件?

Ser*_*kiy 7

好的,我只是想出了如何做到这一点,万一有人需要id.除了专用模型定义部分("定义")之外,还可以进行内联模型描述.上面的代码如下所示:

responses:
    "200":
      description: Matched Objects
      schema:
        type: object
        properties:
          data:
            type: object
            properties:
              authors:
                type: array
                items:
                  $ref: "#/definitions/object_with_id_and_title"
Run Code Online (Sandbox Code Playgroud)