按照 swagger 规范,如何将嵌套对象的 json 定义为 yaml?
Following swagger specifications, how can I define json of nested objects to yaml?
我在 swagger yaml 中定义对象数组时遇到问题。每次我尝试定义 type: yaml 的数组部分时,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?
在模式中,您不需要值,只需要值的描述。
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
已接受的答案无法达到问题所需的输出。 Swagger documentation on examples 解释如何为对象数组添加多个示例:
definitions:
ArrayOfCatalogItems:
type: array
items:
$ref: '#/definitions/CatalogItem'
example:
- id: 38
title: T-shirt
- id: 114
title: Phone
OP其实是对的,只是语法错误:
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
- id:
type: string
value:
type: string
- id:
type: string
value:
type: string
- id:
type: string
value:
type: string
example:
- id: GB
value: GB Great Britain
- id: US
value: US United States
- id: AD
value: AD Andorra, Principles of
我在 swagger yaml 中定义对象数组时遇到问题。每次我尝试定义 type: yaml 的数组部分时,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?
在模式中,您不需要值,只需要值的描述。
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
已接受的答案无法达到问题所需的输出。 Swagger documentation on examples 解释如何为对象数组添加多个示例:
definitions:
ArrayOfCatalogItems:
type: array
items:
$ref: '#/definitions/CatalogItem'
example:
- id: 38
title: T-shirt
- id: 114
title: Phone
OP其实是对的,只是语法错误:
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
- id:
type: string
value:
type: string
- id:
type: string
value:
type: string
- id:
type: string
value:
type: string
example:
- id: GB
value: GB Great Britain
- id: US
value: US United States
- id: AD
value: AD Andorra, Principles of