Asp.Net Core 3.1 集成Swagger
2021-09-16 23:13
标签:ros pen tco int bin etc startup res Fix 引入Nuget包 Swashbuckle.AspNetCore.SwaggerGen Swashbuckle.AspNetCore.SwaggerUI 配置Startup 配置ConfigureServices services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Version = "v1", Title = ApiName }); c.OrderActionsBy(a => a.RelativePath); var xmlFile = "WikiServer.xml";//文件名来源于项目属性==》生成==》输出==》XML文档文件 var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); // 启用xml注释. 该方法第二个参数启用控制器的注释,默认为false. c.IncludeXmlComments(xmlPath, true); }); 配置Configure app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint($"/swagger/v1/swagger.json", $"{ApiName} V1"); //路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件,注意localhost:8001/swagger是访问不到的,去launchSettings.json把launchUrl去掉,如果你想换一个路径,直接写名字即可,比如直接写c.RoutePrefix = "doc"; c.RoutePrefix = ""; });Asp.Net Core 3.1 集成Swagger标签:ros pen tco int bin etc startup res Fix 原文地址:https://www.cnblogs.com/harry7988/p/12319732.html