【问题标题】:How to describe response object in swagger, using yaml?如何使用 yaml 大摇大摆地描述响应对象?
【发布时间】:2015-08-08 07:32:50
【问题描述】:

我们对 /papers/15 有以下 json 响应

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

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

【问题讨论】:

标签: api documentation yaml swagger


【解决方案1】:

好的,我只是想出了如何做到这一点,以防有人需要 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"

【讨论】:

  • 能否请您显示完整的响应和定义?
  • 该对象的meta 对象和total 属性在哪里?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-09
  • 1970-01-01
  • 2018-08-17
  • 1970-01-01
相关资源
最近更新 更多