Forum Discussion

Nixol's avatar
Nixol
Occasional Contributor
4 years ago
Solved

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

5 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    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'
    • Nixol's avatar
      Nixol
      Occasional Contributor

      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.