How to add SwaggerUI back into a .NET 9 Web API project

Swashbuckle.AspNetCore (including SwaggerUI) has been removed from the Web API template in .NET 9.

Since the Swashbuckle project is being continued many teams would just like to stick with it for consistency with their other projects.

The OpenAPI documentation generation aspect of Swashbuckle is now built into .NET 9 but adding the SwaggerUI part back in is super easy:

  • Install the Swashbuckle.AspNetCore.SwaggerUI NuGet package
  • Amend Program.cs to register the SwaggerUI middleware and have it generate from the OpenAPI doc .NET has created.

  • … And optionally amend launchSettings.json to automatically open the browser with /swagger loaded.

    .NET 9 Web API Project commit with above changes:
    https://github.com/davepcallan/APIUIDemo/commit/0e9b1d63e4070e9521e47441ff94116a1951540e

    Leave a Reply

    Your email address will not be published. Required fields are marked *