Swagger Configuration in .Net 8

Swagger Configuration in .Net 8
Install Nuget package in your solution – Swashbuckle.AspNetCore

Use below configuration in your Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.AddAppAuthetication();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();

}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

Add launchUrl in launchSettings.json
{
“$schema”: “http://json.schemastore.org/launchsettings.json”,
“iisSettings”: {
“windowsAuthentication”: false,
“anonymousAuthentication”: true,
“iisExpress”: {
“applicationUrl”: “http://localhost:36830”,
“sslPort”: 44381
}
},
“profiles”: {
“http”: {
“commandName”: “Project”,
“dotnetRunMessages”: true,
“launchBrowser”: true,
“launchUrl”: “swagger”,
“applicationUrl”: “http://localhost:5172”,
“environmentVariables”: {
“ASPNETCORE_ENVIRONMENT”: “Development”
}
},
“https”: {
“commandName”: “Project”,
“dotnetRunMessages”: true,
“launchBrowser”: true,
“launchUrl”: “swagger”,
“applicationUrl”: “https://localhost:7001;http://localhost:5172”,
“environmentVariables”: {
“ASPNETCORE_ENVIRONMENT”: “Development”
}
},
“IIS Express”: {
“commandName”: “IISExpress”,
“launchBrowser”: true,
“launchUrl”: “swagger”,
“environmentVariables”: {
“ASPNETCORE_ENVIRONMENT”: “Development”
}
}
}
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply