OpenAPI, Versioning & Deployment
Generate Swagger/OpenAPI docs, version APIs, and deploy a Minimal API to Azure App Service or containers.
OpenAPI in Minimal APIs
OpenAPI (formerly Swagger) generates interactive API documentation. In .NET 9, AddOpenApi() is built-in. For earlier versions, use Swashbuckle.AspNetCore.
Adding Swagger with Swashbuckle
Install Swashbuckle, configure it in services, and add the middleware to serve the spec and Swagger UI.
// dotnet add package Swashbuckle.AspNetCore
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(opt =>
opt.SwaggerDoc("v1", new() { Title = "Products API", Version = "v1" }));
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}All lessons in this course
- Creating Your First Minimal API
- Route Groups, Parameters & Validation
- Middleware & Filters in Minimal APIs
- OpenAPI, Versioning & Deployment