//1、接口传出接口序列化
#region --JsonSerializerSettings配置--
builder.Services.AddControllers().AddNewtonsoftJson(opt =>
{
// 忽略循环引用
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
// 不使用驼峰
opt.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
#endregion --JsonSerializerSettings配置--
//2、Swagger表头信息
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("V1", new OpenApiInfo { Title = "Jeffrey.PPS.APIs", Version = "V1" });
});
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(s =>
{
s.SwaggerEndpoint("/swagger/V1/swagger.json", "SDS.PPS.API.V1");
});
}
//3.认证&授权
#region -- 认证&授权(同时存在,否则添加属性Authorize不启作用) --
app.UseAuthentication();//认证
app.UseAuthorization();//授权
#endregion -- 认证&授权(同时存在,否则添加属性Authorize不启作用) --
//4、Swagger显示注释信息
#region -- 在Swagger上面显示注释信息 --
builder.Services.AddSwaggerGen(c =>
{
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录
var xmlPath = Path.Combine(basePath, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");//接口action显示注释
//c.IncludeXmlComments(Path.Combine(basePath, "SDS.WebAPI.xml"), true);//接口注释
c.IncludeXmlComments(Path.Combine(basePath, "SDS.API.Application.xml"), true);//实体类注释
});
#endregion -- 在Swagger上面显示注释信息 --
标签:--,app,配置,注释,Path,Net,Swagger,basePath
From: https://www.cnblogs.com/diffknow/p/16743791.html