I have the following schema in 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'
So I have FooResponse and BarResponse. I am getting OneOf matches multiple schema error though I have different required items in FooResponse and BarResponse. It seems like openapi matches two schemas even if there are additional required items in one of the schema.
Is there a way to fix this? I want to use OneOf, but not sure how to differentiate these two schema.
Appreciate the help.
question from:https://stackoverflow.com/questions/65672227/how-to-use-oneof-with-two-similiar-schemas-in-openapi