openapi - 如何区分 OpenAPI 模式中的多个属性?
问题描述
这里的文档解释了当 OpenAPI 模式依赖于属性的值时如何定义鉴别器。在我自己的项目中,我有一个依赖于两个属性值的模式,而不仅仅是一个。我想知道是否有任何方法可以在 OpenAPI 文件中对其进行建模?
假设我们有一个请求列表,其中包含两个必需的枚举属性:
- requestType:它可以是以下值之一:
- 新的
- 老的
- periodType:可以是以下任一值:
- 暂时的
- 永恒的
其余属性的值在某种程度上取决于这两个字段的值。因此,我们希望根据这 2 个字段来区分 4 种可能的模式。我想到的一种可能的解决方案是使用这样的嵌套结构:
ListResponse:
type: array
items:
oneOf:
- $ref: '#/components/schemas/NewRequestResponse'
- $ref: '#/components/schemas/OldRequestResponse'
discriminator:
propertyName: requestType
mapping:
'New':
oneOf:
- $ref: '#/components/schemas/NewTemporaryRequestResponse'
- $ref: '#/components/schemas/NewPermanentRequestResponse'
discriminator:
propertyName: periodType
mapping:
'Temporary': '#/components/schemas/NewTemporaryRequestResponse'
'Permanent': '#/components/schemas/NewPermanentRequestResponse'
'Old':
oneOf:
- $ref: '#/components/schemas/OldTemporaryRequestResponse'
- $ref: '#/components/schemas/OldPermanentRequestResponse'
discriminator:
propertyName: periodType
mapping:
'Temporary': '#/components/schemas/OldTemporaryRequestResponse'
'Permanent': '#/components/schemas/OldPermanentRequestResponse'
uniqueItems: true
但似乎这不是一个有效的模式。那么,怎么可能做到呢?
解决方案
推荐阅读
- r - 将图例添加到 R 中的图形
- matlab - 如何在不使用 for 循环的情况下对不同大小的矩阵的各个部分求和?
- c# - 用于在 Windows 中使用 AuthenticateAsServer() 的 localhost 的 x509 证书
- unicode - Keyman developer 10 将不匹配 Odia 脚本中的规则
- iot - 用于模仿 IoT 代理命令的 NGSI v2 端点是什么?
- ms-access - Jet SQL/MS Access - 按用户查询、任务计数、时间总和
- git - 我怎样才能回到以前的提交,删除我在本地/公共仓库中发布的所有内容?
- java - 模拟 SOAP 请求和响应
- ios - 更改不同屏幕上的导航栏颜色和标题颜色
- python - Python:从csv中提取特定行作为列表