.net core Swagger配置
2024-02-25 01:45:05 790 0
ConfigureService中添加以下代码:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1.1", new OpenApiInfo { Title = "接口文档", Version = "v1.1", Description = "API文档全部由代码自动生成" });
var filePath = Path.Combine(System.AppContext.BaseDirectory, "WebApi.xml");
c.IncludeXmlComments(filePath, true);
});
Configure 中添加以下代码:
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1.1/swagger.json", "接口文档 v1.1");
c.DocumentTitle = "接口文档";
c.DocExpansion(DocExpansion.List);
});