如何在Swagger API中描述嵌套对象?

时间:2019-07-19 06:41:45

标签: yaml swagger

我正在尝试使用Swagger API描述以下用于API端点响应的数据结构。(Swagger描述如下所示)
但是,出现以下错误。
If TypeOf (sender) Is VScrollBar Then Dim scrollBar As VScrollBar = CType(sender, VScrollBar) If TypeOf (scrollBar.Parent) Is KryptonExtendedGrid Then Dim KryptonGrid As KryptonExtendedGrid = CType(scrollBar.Parent, KryptonExtendedGrid) If KryptonGrid.ScrollControl IsNot Nothing Then If scrollBar.Visible Then grdForecast.ScrollBars = ScrollBars.None scrollBar.Visible = False scrollBar.Hide() KryptonGrid.ScrollControl.DownButton.Enabled = True Else KryptonGrid.ScrollControl.DownButton.Enabled = False End If End If End If End If 行应为对象。
我可以知道怎么了吗?

API的实际回报

- smallpower

Swagger 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"
        },
    ]
}  

已根据Helen的评论进行了更新
enter image description here

1 个答案:

答案 0 :(得分:1)

这是properties的正确语法,其中每个属性是一个$ref强化模式的数组:

            properties:
              smallpower:
                type: array
                items:
                  $ref: '#/components/schemas/SmallPower'
              oa:
                type: array
                items:
                  $ref: '#/components/schemas/OA'
              light:
                type: array
                items:
                  $ref: '#/components/schemas/light'