swagger Swashbuckle -如何更改服务的显示标题?

gfttwv5a  于 2023-02-04  发布在  其他
关注(0)|答案(1)|浏览(261)

当我使用swashbuckle运行.NET核心服务时,它显示的标题(在所有资源之上)是从程序集名称派生的。

如何指定要显示在宣传页上的我自己的标题?

(The页面上显示的标题与文档标题不同,后者可以通过传递到app.UseSwaggerUI()方法中的options.DocumentTitle进行修改。)
edit:这是我当前的设置代码-它是随C#webapi模板一起提供的:

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

vtwuwzda1#

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

相关问题