Home > Software design >  Swashbuckle - How do I change the displayed title of the service?
Swashbuckle - How do I change the displayed title of the service?

Time:02-02

When I run a .NET Core service using swashbuckle, the title it displays (above all the resources) is derived from the assembly name.

How can I specify my own title to appear on the swagger page?

(The title displayed on the page is distinct from the document title, which can be modified via options.DocumentTitle passed into the app.UseSwaggerUI() method.)

edit: This is my current setup code - it's what comes out of the box with the C# webapi template:

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

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();

CodePudding user response:

builder.Services.AddSwaggerGen(opt => opt.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
{
    Title = "Title of the service",
    Description = "Description of the service"
}));

enter image description here

  • Related