I have a scenario where my ASP.NET WEB API returns 2 different models depending upon the request object. I am using swagger UI (through swashbuckle) to document my ASP.NET WEB API and currently is unable to find a way to document these 2 models against 1 ASP.NET WEB API action. I have tried googling but was not fruitful. any help will be appreciated.
Asked
Active
Viewed 294 times
0
-
Can you provide some sample code of your action? – Helder Sepulveda Aug 23 '17 at 12:42
-
It looks like what you need to use is ***SwaggerResponse*** but is hard to know for sure without a sample code... ```[SwaggerResponse(HttpStatusCode.OK, "List of customers", typeof(IEnumerable
))]``` – Helder Sepulveda Aug 23 '17 at 12:45
1 Answers
1
The OpenAPI (formerly known as Swagger) specification version 2 does not have any way of describing two different models for the same operation. With the new OpenAPI V3 you can use a schema with the oneOf
attribute to describe multiple possible response shapes.
However, there isn't much tooling available yet for V3.

Darrel Miller
- 139,164
- 32
- 194
- 243
-
Darrel Miller, I do have same opinion but I was not sure. Thank you for making me sure :) – Umer Hayyat Aug 25 '17 at 10:48