【发布时间】:2021-01-11 18:04:12
【问题描述】:
我在 openapi 中有以下架构
/submit:
post:
description: Submit info
x-openapi-router-controller: abc.def
operationId: submit_info
requestBody:
description: Submit request
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/SubmitRequest'
responses:
200:
description: submitted successfully
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/FooResponse'
- $ref: '#/components/schemas/BarResponse'
FooResponse:
type: object
required:
- id
- value
properties:
id:
type: string
description: id
example: '1234'
value:
type: string
description: value
example: 'foo'
BarResponse:
type: object
required:
- id
- value
- data
properties:
id:
type: string
description: id
example: '1234'
value:
type: string
description: value
example: 'foo'
data:
type: object
required:
- transaction_id
description: Data associated bar response
properties:
transaction_id:
type: string
description: transaction id
example: 'c2345'
所以我有 FooResponse 和 BarResponse。尽管 FooResponse 和 BarResponse 中有不同的必需项,但我收到 OneOf 匹配多个模式错误。即使其中一个架构中有其他必需项,openapi 似乎也匹配两个架构。
有没有办法解决这个问题?我想使用 OneOf,但不确定如何区分这两种模式。
感谢您的帮助。
【问题讨论】:
标签: schema openapi openapi-generator