6

swagger yaml でオブジェクトの配列を定義する際に問題が発生しています。yaml の type: array 部分を定義しようとするたびに、Swagger エディターでエラーが発生します。私はそれを定義しましたが、エラーを出しているので正しくありません。以下は、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をどのように定義すればよいか教えてもらえますか?

4

3 に答える 3

17

スキーマでは、値は必要なく、値の説明のみが必要です。

CountryCombo:
    type: object
    properties:
        options:
            type: object
            properties:
                option:
                    type: array
                    items:
                        type: object
                        properties:
                          id:
                            type: string
                          value:
                            type: string
于 2016-03-14T20:48:22.760 に答える
16

上記の答えも正しいですが、これはすでに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
于 2016-03-28T12:28:29.347 に答える