RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.69k stars 1.23k forks source link

Dealing with multiple successful responses in C# #1782

Open molnarm opened 5 years ago

molnarm commented 5 years ago

Example code here (templates a bit customized to pass the REST resource to logging, but no other changes in response processing).

It is perfectly possible that the specification for an operation has multiple 2XX codes for different results. My example is a POST with 201 for successful creation and 202 for the request still being processed, another case could be 202 for ongoing processing and 204 and successful creation/deletion/whatever.

In these scenarios, NSwag picks 200 or the first successful response as return type for the method, and for all other status codes (including successful 2XX ones), it throws an exception with the response inside.

Of course I realise that it's not possible to have multiple return types, is there any best practice or recommended structure for deailng with such a situation?

RicoSuter commented 5 years ago

Related: https://github.com/RSuter/NSwag/issues/1259