grinh
grinh

Reputation: 169

How to tell swagger that particular response has no response type except status code?

I'm creating swagger document for ASP.net API. I want to show in swagger that there is no response (other than status code) for any given status code. I have following attributes on my method:

enter image description here

This gives me following result in swagger:

enter image description here

As you can see status codes 200 and 500 does not have response type and this is what I want. But 401 has unnecessary response type. I want to get rid of it. The same is true for all other status codes (except 200 and 500). I've tried adding EmptyResult but this still produces empty brackets as a response:

enter image description here

enter image description here

Do you maybe know how I can configure this? I'm using Swashbuckle.

Upvotes: 0

Views: 696

Answers (1)

NotFound
NotFound

Reputation: 6172

In the newer versions of ASP.NET CORE errors will produce an instance of ProblemDetails. You can disable it in ur Startup using the following code:

services
    .AddControllers() //or addMvc() for older projects
    //below the important part to add
    .ConfigureApiBehaviorOptions(options =>
    {
        options.SuppressMapClientErrors = true;
    });

Upvotes: 2

Related Questions