Originally posted by Nixol on November 15, 2020
can I use two POST methods for the same path with each operation having its own request body? If it is not possible, how cab I achieve this? I use OpenApi 3.0.3
Originally posted by Nixol on November 15, 2020
can I use two POST methods for the same path with each operation having its own request body? If it is not possible, how cab I achieve this? I use OpenApi 3.0.3
Originally posted by HKosova on November 16, 2020
OpenAPI only allows one POST/GET/etc. operation per path, but you can define multiple possible request bodies by using oneOf:
paths:
/something:
post:
operationId: createSomething
requestBody:
required: true
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Body1'
- $ref: '#/components/schemas/Body2'
Originally posted by Nixol on November 16, 2020
Thanks HKosova for your explanation.
Could you also assist to answer the following followup questions:
Originally posted by HKosova on November 16, 2020
No.
No. You can use oneOf to define the possible response schemas, but OpenAPI doesn’t support request/response correlation.
Here’s a related feature request you can track:
Originally posted by Nixol on February 14, 2021
Is there any plans to include the previously mentioned scenarios in future releases? It will be great if this can be done. Thanks
Originally posted by HKosova on February 14, 2021
Hi Nixol,
I agree this can be useful. The best way to show your interest is to upvote the existing feature request in the OpenAPI Specification repository and/or add a comment there with your use case: