.NET|--.Net Core 6 |--Swagger显示注释信息

1.输出xml文件

选中API项目,鼠标右击,选中"属性",
勾选"生成>>输出>>文档文件"

修改Program.cs中配置

//var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSwaggerGen
(
    options =>
    {
        options.SwaggerDoc("v1", new OpenApiInfo()
        {
            Title = "Title",
            Version = "v1",
            Description = "Description",
        });
        var path = Path.Combine(AppContext.BaseDirectory, "TileMapApi.xml");
        options.IncludeXmlComments(path, true);
        options.OrderActionsBy(_ => _.RelativePath);
    }
);

//var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();

posted @ 2023-08-27 22:32  zh89233  阅读(273)  评论(0编辑  收藏  举报