Search code examples
swaggerswashbuckleasp.net5

How to use SwaggerResponse after uprading Swashbuckle in net5 web api?


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

  • either use the SwaggerResponse attribute in latest Swashbuckle, or
  • convert the existing code?

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