cancel
Showing results for 
Search instead for 
Did you mean: 

OpenAPi 3.0.3 - can I use two POST methods for the same path - each with its own request body?

SOLVED
Nixol
Occasional Contributor

OpenAPi 3.0.3 - can I use two POST methods for the same path - each with its own request body?

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

1 ACCEPTED SOLUTION

Accepted Solutions
HKosova
Moderator

Re: OpenAPi 3.0.3 - can I use two POST methods for the same path - each with its own request body?

1. No.

2. 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:

Support an operation to have multiple specifications per path (e.g. multiple POST operation per path... 


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

5 REPLIES 5
HKosova
Moderator

Re: OpenAPi 3.0.3 - can I use two POST methods for the same path - each with its own request body?

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'

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Nixol
Occasional Contributor

Re: OpenAPi 3.0.3 - can I use two POST methods for the same path - each with its own request body?

Thanks @HKosova for your explanation. 

Could you also assist to answer the following followup questions:
1. can each of the requests have a different tag?  eg. Body1 has "TagA" and body2 has "TagB"
2.  can each of the requests have a corresponding response? e.g. if Body1 is used, then the response will be Response1, if Body2 is used then the response will be Response2.

 

HKosova
Moderator

Re: OpenAPi 3.0.3 - can I use two POST methods for the same path - each with its own request body?

1. No.

2. 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:

Support an operation to have multiple specifications per path (e.g. multiple POST operation per path... 


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

Nixol
Occasional Contributor

Re: OpenAPi 3.0.3 - can I use two POST methods for the same path - each with its own request body?

Is there any plans to include the previously mentioned scenarios in future releases?  It will be great if this can be done.  Thanks

HKosova
Moderator

Re: OpenAPi 3.0.3 - can I use two POST methods for the same path - each with its own request body?

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:

https://github.com/OAI/OpenAPI-Specification/issues/182


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements