首先添加"SwaggerGenerator": "1.1.0","SwaggerUi": "1.1.0" 须要注意的是这两个组件是我对Swashbuckle的从新封装,由于当前版本对泛型会报错。json
在ConfigureServices 中添加:app
1 services.ConfigureSwaggerGen(options => 2 { 3 4 options.SwaggerDoc("v1", 5 new Info 6 { 7 Version = "v1", 8 Title = "ryan API", 9 } 10 ); 11 options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, Assembly.GetEntryAssembly().GetName().Name+".xml")); 12 options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, Assembly.GetEntryAssembly().GetName().Name + ".Application.xml")); 13 options.DescribeAllEnumsAsStrings(); 14 });
在config方法中添加:spa
1 if (HostingEnvironment.IsDevelopment()) 2 { 3 app.UseSwagger(); 4 app.UseSwaggerUi(c=>c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs")); 5 }
在controller中须要添加attribute,不然文档会生成失败。code
齐活,在浏览取中输入 http:{youhost}/swagger 便可访问了。xml