dotnet6 swagger

2022-10-27  本文已影响0人  ljt001
// Program.cs
// nuget包 <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers().AddNewtonsoftJson();
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(c =>
{
    // 本例此处是处理dto重名,比如存在同名类:Demo.ContractModel.Student和Demo.SdkClient.Student
    c.CustomSchemaIds(type => type.ToString());
   // 显示注释,本例需要在以下两个csproj项目文件中勾选“生成包含API文档的文件”以便生成xml文件
    c.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Demo.HostService.xml"));
    c.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Demo.ContractModel.xml"));
});
app.UseSwagger();
app.UseSwaggerUI();

app.UseAuthorization();
app.MapControllers();
app.Run();
上一篇下一篇

猜你喜欢

热点阅读