教程:http://www.wmpratt.com/swagger-and-asp-net-web-api-part-1/
1:安装Dll: https://www.nuget.org/packages/Swashbuckle/
2:配置Swagger
GlobalConfiguration.Configuration .EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API")) .EnableSwaggerUi();
3:访问 xxx/swagger/ui/index#
注意:Controller的命名规范,先保证访问保证Controller
4:启用XML文档注释
4.1:VS 启用编译的XML注释
4.2:更新配置:
GlobalConfiguration.Configuration .EnableSwagger(c => { c.SingleApiVersion("v1", "SwaggerDemoApi"); c.IncludeXmlComments(string.Format(@"{0}inSwaggerDemoApi.XML", System.AppDomain.CurrentDomain.BaseDirectory)); }) .EnableSwaggerUi();
添加元素xml