我想建模一个响应对象,其中包含 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'
下一版本的 OpenAPI 规范 (3.0) 将支持这一功能,以下是有关此功能的相关讨论:
https://github.com/OAI/OpenAPI-Specification/issues/57 https://github.com/OAI/OpenAPI-Specification/issues/57
下面是一个示例(在上面的 URL 中提供):
{
"oneOf": [
{ "$ref": "Cat" },
{ "$ref": "Dog" }
]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)