Yaml 如何在Swagger API中描述嵌套对象?
我试图在下面描述使用Swagger API的API端点响应的数据结构。(Swagger描述如下所示)Yaml 如何在Swagger API中描述嵌套对象?,yaml,swagger,Yaml,Swagger,我试图在下面描述使用Swagger API的API端点响应的数据结构。(Swagger描述如下所示) 但是,我得到以下错误。 行-smallpower应为对象。 我能知道怎么了吗 实际API返回值 { "smallpower": [ { "A": "A", "B": 11.9, "C": true, "D": "D" }, { "
但是,我得到以下错误。
行
-smallpower
应为对象。我能知道怎么了吗 实际API返回值
{
"smallpower": [
{
"A": "A",
"B": 11.9,
"C": true,
"D": "D"
},
{
"A": "A",
"B": 11.9,
"C": true,
"D": "D"
},
],
"oa": [
{
"A": "A",
"B": 11.9,
"C": true,
"D": "D"
},
{
"A": "A",
"B": 11.9,
"C": true,
"D": "D"
},
],
"light": [
{
"A": "A",
"B": 11.9,
"C": true,
"D": "D"
},
{
"A": "A",
"B": 11.9,
"C": true,
"D": "D"
},
]
}
招摇过市API规范
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: object
properties:
- smallpower:
type: object
schema:
$ref: '#/components/schemas/SmallPower'
- oa:
type: object
schema:
$ref: '#/components/schemas/OA'
- light:
type: object
schema:
$ref: '#/components/schemas/light'
根据海伦的评论更新
以下是
属性的正确语法,其中每个属性都是$ref
引用架构的数组:
属性:
smallpower:
类型:数组
项目:
$ref:“#/components/schemas/SmallPower”
办公自动化:
类型:数组
项目:
$ref:“#/components/schemas/OA”
灯光:
类型:数组
项目:
$ref:“#/components/schemas/light”
以下是属性的正确语法,其中每个属性都是$ref
引用架构的数组:
属性:
smallpower:
类型:数组
项目:
$ref:“#/components/schemas/SmallPower”
办公自动化:
类型:数组
项目:
$ref:“#/components/schemas/OA”
灯光:
类型:数组
项目:
$ref:“#/components/schemas/light”
谢谢您的回答。它几乎是固定的。但我希望值是对象的数组,而不仅仅是对象。你能帮我修一下吗?我在上面添加了现状图片,谢谢你的回答。它几乎是固定的。但我希望值是对象的数组,而不仅仅是对象。你能帮我修一下吗?我在上面添加了现状图片