4

I need to support two kinds of request-bodies for the same endpoint and same method (POST). Is it possible in Swagger?

This is important because both request-bodies are valid and a user can send either one of them. More specifically,

RequestBody 1:

{ param1: value1 param2: value2 param3: { param3Key1: x1 param3Key2: x2 ... } } 

RequestBody 2:

{ param1: value1 param2: value2 param4: { differentKey1: y1 differentKey2: y2 ... } } 

Is there a way to document this situation in Swagger?

One way to do that would be keeping both param3 and param4 in the docs. But, I want the users to specifically know that only one of them needs to be passed. I want to have an altogether different request-body for both of the situations.

1 Answer 1

2

Couldn't find a straight-way. Here's a workaround that I'm following now:

Suppose the endpoint is /endpoint. I can create 2 endpoints in the swagger-ui by appending # followed by a string:

/endpoint#1

/endpoint#2

I can then define both my request-bodies separately under each of these endpoints. The curl command in swagger will hide the hash - so, both the endpoint are basically the same.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.