swagger 集成asp.net Core2.1
首先通过nuget 安装 Swashbuckle.AspNetCore
1.在startup.cs 的configureService
services.AddAutoMapper(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "igbomWeb API", Version = "v1" }); // 为 Swagger JSON and UI设置xml文档注释路径 //var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径) var basePath = "swagger"; var xmlPath = Path.Combine(basePath, "igbomWebAPI.xml"); c.IncludeXmlComments(xmlPath); });
2.在configure
//启用中间件服务生成Swagger作为JSON终结点 app.UseSwagger(); //启用中间件服务对swagger-ui,指定Swagger JSON终结点 app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "igbomWeb API V1"); c.RoutePrefix = string.Empty; });
3.通过vs2017配置,项目属性=》生成