按照大张旗鼓的规范,如何将嵌套对象的json定义为yaml? [英] Following swagger specifications, how can I define json of nested objects to yaml?

查看:499
本文介绍了按照大张旗鼓的规范,如何将嵌套对象的json定义为yaml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用摇摇欲坠的Yaml定义对象数组时遇到问题.每次我尝试定义yaml的type:array部分时,Swagger编辑器都会出错.我定义了它,但它不正确,因为它给出了一个错误. 以下是我要在swagger yaml中定义的json.

I am having a problem in defining the array of objects in swagger yaml. Swagger editor is giving an error everytime I try to define the type: array part of the yaml. I defined it, but it is not right as it is giving an error. Following is the json I am trying to define in swagger yaml.

{
    "CountryCombo": {
        "options": {
            "option": [{
                "id": "GB",
                "value": "GB Great Britain"
            }, {
                "id": "US",
                "value": "US United States"
            }, {
                "id": "AD",
                "value": "AD Andorra, Principality of"
            }]
        }
    }
}

我像这样将json定义为宽泛的yaml,但出现错误:

I defined this json into swagger yaml like this but it is giving an error:

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

任何人都可以建议我如何按照摇摇欲坠的规范在yaml中定义此json?

Can anyone suggest me how would I define this json in yaml following swagger specifications?

推荐答案

在架构中,您不希望拥有值,仅拥有值的描述.

In a schema, you don't want to have the values, only the description of the values.

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

这篇关于按照大张旗鼓的规范,如何将嵌套对象的json定义为yaml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆