簡體   English   中英

Swashbuckle - 如何更改服務的顯示標題?

[英]Swashbuckle - How do I change the displayed title of the service?

當我使用 swashbuckle 運行 .NET Core 服務時,它顯示的標題(在所有資源之上)源自程序集名稱。

如何指定我自己的標題出現在 swagger 頁面上?

(頁面上顯示的標題與文檔標題不同,可以通過傳入app.UseSwaggerUI()方法的options.DocumentTitle進行修改。)

編輯:這是我當前的設置代碼——它是 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();

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

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM