Search code examples
asp.net-core-webapiswashbuckle.aspnetcore

Why adding ApiExplorer breaks Swashbuckle?


After I added

        services.AddVersionedApiExplorer();

previously normally working Swashbuckle started showing blank Swagger json with default version and no endpoints in it.


Solution

  • It appears that ApiExplorer requires presence of ApiControllerAttribute at API controllers. So if you don't have your controllers decorated with this attribute, everything will work perfectly up to the point when you add ApiExplorer, and after that Swachbuckle will behave like there are no controllers in your project at all (apparently, that's what ApiExplorer tells it).

    Decorating your controllers with [ApiController] fixes this issue. In case you don't want to bother with writing RegExp to apply those changes for you, or even go into every single controller file to paste it manually, [assembly:ApiController] will handle all of them at once.