[英]swagger 3: schema for dictionary of dictionaries
我想建模一個模式,其中響應是字典的字典:
{
'id1': {
'type': 'type1',
'active': true,
},
'id2': {
'type': 'type2',
'active': false,
},
...
...
}
我已經定義:
components:
schemas:
accountData:
type: object
required:
- type
- active
properties:
type:
type: string
active:
type: boolean
accounts:
type: object
additionalProperties:
type: object
properties:
account-id:
type: object
$ref: '#/components/schemas/accountData'
現在我想定義“#/components/schemas/accounts”,它是“#/components/schemas/account”的重復字典。
我對 OpenApi 3 很陌生,我無法弄清楚如何去做。
你快到了。 additonalProperties
指定的模式對應於<key, value>
字典中的值類型。 在您的示例中,值是accountData
對象,因此您應該使用:
components:
schemas:
...
accounts:
type: object
additionalProperties:
$ref: '#/components/schemas/accountData'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.