dotnet6 swagger

// Program.cs
// nuget包 

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

你可能感兴趣的:(dotnet6 swagger)