asp.net-coreswaggerasp.net-core-webapiswashbuckleasp.net-core-5.0

How to use SwaggerResponse after upgrading Swashbuckle in ASP.NET Core WebAPI


We have a Web API with ~150 controllers (~500 methods) which we upgraded from Core2.2 to net5.0 and along with it we upgraded the Swashbuckle package.

The old version of Swashbuckle used SwaggerResponse attribute to display information on SwaggerUI and we used it heavily over our ~500 methods.

At some point the SwaggerResponse attribute was deprecated and the recommended solution is a different approach: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/159

Is there a way to


Solution

  • It's recommended that you use ProduceResponseTypeAttribute, However you can still use SwaggerResponse via the NuGet package Swashbuckle.AspNetCore.Annotations.

    The type SwaggerResponse wasn't completely removed it was just moved away from the main Swashbuckle package namely Swashbuckle.AspNetCore to an optional extra package Swashbuckle.AspNetCore.Annotations