首先添加"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