Swagger 生成API文档

1.打开程序包管理控制台输入:

Install-Package Swashbuckle

2.打开App_Start文件夹下的SwaggerConfig.cs文件找到

c.IncludeXmlComments 

替换为

c.IncludeXmlComments(GetXmlCommentsPath(thisAssembly.GetName().Name));

3.添加方法

protected static string GetXmlCommentsPath(string name)
{
      return string.Format(@"{0}in{1}.XML", AppDomain.CurrentDomain.BaseDirectory, name);
}

4.右键项目->属性->生成->勾选(XML文档文件)->保存

5.访问地址

http://localhost:15416/swagger/ui/index

如下图:

官方地址: Swagger

原文地址:https://www.cnblogs.com/zevfang/p/6398382.html