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
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
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

3 REPLIES 3
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. ⬇️⬇️⬇️
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.

 

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

New Here?
Join us and watch the welcome video:
Announcements