Blog Logo
TAGS

Generate ASP.NET Core OpenAPI Spec At Build Time

I recently worked with Swashbuckle, a .NET package that can generate Swagger 2.0 and OpenAPI 3.0 specifications from existing ASP.NET Core solutions. The benefit of the library is we can write HTTP APIs and get automatically generated documentation. This post will see how to configure Swashbuckle within an ASP.NET Core project to generate a static OpenAPI specification file using the CLI tooling. Starting with a brand new ASP.NET Core Web API application, well see Swashbuckle is set up by default. We also see that the SwaggerMiddleware and the Swagger UI are registered in the Configure method. The first step is to make sure our project can call the Swashbuckle CLI tooling from the context of our solution. Well then follow it up with the installation of the Swashbuckle CLI tooling. We should now be able to run the tooling as a build step.