38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Mvc.Controllers;
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
namespace Bunny.WebApi.Configuration;
|
|
|
|
public static class Knife4Net
|
|
{
|
|
/// <summary>
|
|
/// 配置 Knife4j 文档
|
|
/// </summary>
|
|
public static void AddKnife4Net(this WebApplicationBuilder builder)
|
|
{
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen(options =>
|
|
{
|
|
// 读取设置的文档,将注释读取
|
|
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "Swagger.xml"), true);
|
|
|
|
// 设置文档版本和说明
|
|
options.SwaggerDoc("v1", new OpenApiInfo
|
|
{
|
|
Title = "Bunny 文档", Version = "v1", Description = "文档说明"
|
|
});
|
|
|
|
|
|
options.AddServer(new OpenApiServer
|
|
{
|
|
Url = "http://localhost:8800"
|
|
});
|
|
|
|
options.CustomOperationIds(apiDesc =>
|
|
{
|
|
var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
|
|
return controllerAction?.ControllerName + "-" + controllerAction?.ActionName;
|
|
});
|
|
});
|
|
}
|
|
} |