.net 安装Swagger

官网:http://swagger.io/

教程: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}\bin\SwaggerDemoApi.XML",           
                           System.AppDomain.CurrentDomain.BaseDirectory));
    })
  .EnableSwaggerUi();

添加元素xml

posted @ 2016-04-01 14:21  GrayGuo  阅读(530)  评论(0编辑  收藏  举报