Ask a Question

One Url

RoyDavinci
New Member

One Url

I have a single ednpoint and would like to create several post request to it with different response bodies, how do I manage this?

1 REPLY 1
ponelat
Staff

Re: One Url

Hi @RoyDavinci 

 

It's not recommended practice to return different responses for the same request. But here is the simplest approach (assumes you're using OpenAPI 3.x, not OpenAPI/Swagger 2.0)...

 

Using `oneOf`.

You can use the `oneOf` keyword for when your response is one of the following. Eg:

      responses:
        '200':
          description: Multiple response types
          content:
            application/json:
              schema:
                oneOf:
                - $ref: '#/components/schemas/Dog'
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Hamster'

 

See full example: https://gist.github.com/ponelat/7ba6f1ec61a6b7e0054bf0b3a7f80f0b

Further documentation on responses: https://swagger.io/docs/specification/describing-responses/

 

cancel
Showing results for 
Search instead for 
Did you mean: