【问题标题】:Model response containing array of different object types in swagger模型响应包含 swagger 中不同对象类型的数组
【发布时间】:2017-04-29 00:06:03
【问题描述】:

我想在 swagger 中建模一个包含不同类型对象数组的响应对象,如下所示:

{
   "table": [
        {
          "user" : []
        },
        {
          "customer": []
        },
        {
           "employee": []
        }
    ]
}

我尝试了下面的解决方案,但它将所有属性包装在一个对象中 { [ { "user": [], "customer": [] } ] }。

  responses:
    200:
      schema:
        type: array
        items:
          type: object
          properties:
            user:
              type: array
              items:
                $ref: '#/definitions/User'
            customer:
              type: array
              items:
                $ref: '#/definitions/Customer'
            employee:
              type: array
              items:
                $ref: '#/definitions/Employee' 

【问题讨论】:

标签: swagger


【解决方案1】:

OpenAPI 规范 (3.0) 的下一个版本将支持该功能,以下是有关此功能的相关讨论:

https://github.com/OAI/OpenAPI-Specification/issues/57

这是一个示例(在上面的 URL 中提供):

{
  "oneOf": [
    { "$ref": "Cat" },
    { "$ref": "Dog" }
  ]
}

【讨论】:

    猜你喜欢
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2018-08-09
    相关资源
    最近更新 更多