Sunday, February 1, 2026

Configuring Swagger in Web API 10

Web API 10 doesn't come with Swagger support. It can be added by adding a reference to Swashbucke.AspNetCore, Adding SwaggerGen to Service, use it in the middleware and making alterations in launchSettins.json.



Program.cs
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
launchSettings.json
"http": {
  ...
  "launchBrowser": true,
  "launchUrl": "swagger",
  "applicationUrl": "http://localhost:5294",
  ...
  }

No comments:

Post a Comment