java中匿名数组_Swagger UI:数组中的多个匿名对象
對象數(shù)組的定義如下:
type: array
items:
type: object
properties:
prop1:
type: string
prop2:
type: integer
# etc.
在您的示例中,響應(yīng)包含具有屬性 balanceDisplaySettings 的對象,并且此屬性包含對象數(shù)組 . 這可以定義如下:
paths:
/Path:
get:
responses:
200:
description: OK
schema:
type: object
properties:
balanceDisplaySettings:
type: array
items:
type: object
properties:
type:
type: string
label:
type: string
visible:
type: boolean
primary:
type: boolean
請注意,架構(gòu)定義了響應(yīng)結(jié)構(gòu),這意味著您無需在任何位置指定實際值( "Balance" , "AvailableBalance" 等) . 但是,如果要在Swagger UI中顯示帖子(包含2個對象的數(shù)組)中的示例,可以像下面這樣添加它:
balanceDisplaySettings:
type: array
items:
type: object
properties:
type:
type: string
label:
type: string
visible:
type: boolean
primary:
type: boolean
example: #
- type: Balance
label: Current
visible: true
primary: false
- type: AvailableBalance
label: Available
visible: true
primary: true
最后,您可能希望拆分內(nèi)聯(lián)嵌套模式以使規(guī)范更加模塊化 .
paths:
/Path:
get:
responses:
200:
description: OK
schema:
$ref: '#/definitions/MyResponseObject'
# |
definitions: # |
# TODO: better name # |
MyResponseObject: #
type: object
properties:
balanceDisplaySettings:
type: array
items:
$ref: '#/definitions/BalanceDisplaySetting'
example: # |
- type: Balance # |
label: Current # |
visible: true # |
primary: false # |
- type: AvailableBalance # |
label: Available # |
visible: true # |
primary: true # |
# |
BalanceDisplaySetting: #
type: object
properties:
type:
type: string
example: Balance
label:
type: string
example: Current
visible:
type: boolean
boolean:
type: boolean
總結(jié)
以上是生活随笔為你收集整理的java中匿名数组_Swagger UI:数组中的多个匿名对象的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在 CCR 环境中使用 Exchange
- 下一篇: linux虚拟光驱挂载方法,Linux操