swagger 3:词典词典的模式
我想建模一个模式,其中响应是字典字典:swagger 3:词典词典的模式,swagger,swagger-editor,openapi,Swagger,Swagger Editor,Openapi,我想建模一个模式,其中响应是字典字典: { 'id1': { 'type': 'type1', 'active': true, }, 'id2': { 'type': 'type2', 'active': false, }, ... ... } 我定义了: components: schemas: accountData: type: object required: - type
{
'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”的重复字典
我对OpenAPI3非常陌生,我不知道怎么做。你就快到了。
附加属性
中指定的架构对应于
字典中的值类型。在您的示例中,值是accountData
对象,因此您应该使用:
组件:
模式:
...
账户:
类型:对象
其他属性:
$ref:“#/components/schemas/accountData”
您尝试过什么?那怎么不起作用?看看这是否有帮助:,这样您就有了一个
地图。查看我之前评论中链接问题的答案。这些答案是针对OpenAPI 2.0的,因此将定义
替换为组件.模式
,以适应3.0语法。@helen我已更新了问题。您能检查一下我是否做得对吗?帐户架构中的键在哪里?@ArindamChoudhury:在您的示例中,键是'id1'
,'id2'
等。在OpenAPI中,键总是字符串,没有明确定义。@Helen,您可能知道-我如何使用java注释做到这一点?@DanBrandt我不知道,抱歉。考虑java注释。