SWAGGER 3:词典的模式 [英] swagger 3: schema for dictionary of dictionaries
本文介绍了SWAGGER 3:词典的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要为响应是词典词典的架构建模:
{
'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/SCHEAS/ACCOUNTS’,它是‘#/Components/SCHEAS/ACCOUNTS’的重复词典。
我对OpenApi 3非常陌生,我不知道如何操作。
推荐答案
您就快成功了。additonalProperties
中指定的架构对应于<key, value>
词典中的值类型。在您的示例中,这些值是accountData
对象,因此您应该使用:
components:
schemas:
...
accounts:
type: object
additionalProperties:
$ref: '#/components/schemas/accountData'
这篇关于SWAGGER 3:词典的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文