yaml - OpenAPI 3 中等效的 XSD 选择
问题描述
我正在 OpenAPI 中构建一个 API,并希望构建与此 XSD 等效的东西:
<xs:complexType name="InputData">
<xs:complexContent>
<xs:sequence>
<xs:element name="input1" type="string" minOccurs="1" maxOccurs="1"/>
<xs:element name="input2" type="double" minOccurs="1" maxOccurs="1"/>
<xs:choice>
<xs:element name="input3A" type="my:dataType" minOccurs="1" maxOccurs="1"/>
<xs:element name="input3B" type="my:dataType" minOccurs="1" maxOccurs="1"/>
</xs:choice>
</xs:sequence>
</xs:complexContent>
</xs:complexType>
我能来的最接近的是:
components:
schemas:
MyDataType:
type: object
properties:
val1:
type: string
val2:
type: number
InputData:
type: object
properties:
input1:
type: string
input2:
type: string
input3:
oneOf:
- $ref: '#/components/schemas/MyDataType'
- $ref: '#/components/schemas/MyDataType'
但是,它不允许名称input3A
或input3B
指定我提供的输入。
有什么帮助吗?
解决方案
这里相当于你的 XSD:
components:
schemas:
MyDataType:
type: object
properties:
val1:
type: string
val2:
type: number
InputData:
allOf:
- type: object
properties:
input1:
type: string
input2:
type: string
required: [input1, input2]
- type: object
oneOf:
- properties:
input3A:
$ref: '#/components/schemas/MyDataType'
required: [input3A]
- properties:
input3B:
$ref: '#/components/schemas/MyDataType'
required: [input3B]
推荐阅读
- c# - 可能导致此错误的原因:“csc.exe”以代码-2146232576 退出
- macos - 如何在容器内使用与在主机上访问相同的 url 访问服务
- xslt - 有没有办法制作整页表?
- vue.js - 添加拖放到 vuetify 的选择
- linux - Oracle Developer Studio 12.6 Fortran 编译器:ieee_arithmetic_semantics:断言“0”失败
- css - 框框内的标题 - CSS,前端开发 - UX
- rabbitmq - RabbitMQ -- Unable to Execute Commands due to "libtinfo.so.6" error
- reactjs - Reactjs(Typescript) - 在 Select 字段中连接数组
- scheduled-tasks - 这个调度器表达式 -> *~*~*~*~*/6~0~0 是什么意思?
- python-3.x - 将包含关键字的行附加到上一行