遵循swagger规范,如何将嵌套对象的json定义到yaml?

遵循swagger规范,如何将嵌套对象的json定义到yaml?,json,swagger,swagger-ui,swagger-2.0,swagger-editor,Json,Swagger,Swagger Ui,Swagger 2.0,Swagger Editor,我在定义swagger yaml中的对象数组时遇到问题。每次我试图定义yaml的type:array部分时,Swagger editor都会给出一个错误。我定义了它,但它不正确,因为它给出了一个错误。 以下是我试图在swagger yaml中定义的json { "CountryCombo": { "options": { "option": [{ "id": "GB", "value"

我在定义swagger yaml中的对象数组时遇到问题。每次我试图定义yaml的type:array部分时,Swagger editor都会给出一个错误。我定义了它,但它不正确,因为它给出了一个错误。 以下是我试图在swagger yaml中定义的json

{
    "CountryCombo": {
        "options": {
            "option": [{
                "id": "GB",
                "value": "GB Great Britain"
            }, {
                "id": "US",
                "value": "US United States"
            }, {
                "id": "AD",
                "value": "AD Andorra, Principality of"
            }]
        }
    }
}
我像这样将这个json定义为swagger yaml,但它给出了一个错误:

CountryCombo:
    type: object
    properties:
        options:
            type: object
            properties:
                option:
                    type: array
                    items:
                        - id:
                            type: string
                            description: GB
                          value:
                            type: string
                            description: GB Great Britain
                        - id:
                            type: string
                            description: US
                          value:
                            type: string
                            description: US United States
                        - id:
                            type: string
                            description: AD
                          value:
                            type: string
                            description: AD Andorra, Principality of

有谁能建议我如何按照swagger规范在yaml中定义这个json吗?

在模式中,您不想要值,只想要值的描述

CountryCombo:
    type: object
    properties:
        options:
            type: object
            properties:
                option:
                    type: array
                    items:
                        type: object
                        properties:
                          id:
                            type: string
                          value:
                            type: string

上述答案也是正确的,但我已经在yaml中实现了这一点。我发现我还可以通过创建另一个定义来定义数组

CountryCombo:
    type: object
    properties:
        options:
            type: object
            properties:
                option:
                    type: array
                    items:
                        $ref: '#/definitions/Country_row'

Country_row:
    type: object
    properties:
      id:
        type: string
      value:
        type: string

我喜欢在几个地方重复使用Country_row定义的场景中使用此版本。这绝对是最好的解决方案: