Swagger的xml注释在文档UI中未显示,不确定我是否遗漏了什么..至少有人指导我这是一个bug。
步骤1:创建一个全新的ASP.NET Web API项目。 步骤2:创建了一个Web API项目。 步骤3:安装了Swashbuckle 5.6.0 NuGet包。 步骤4:启用生成XML文档文件(项目属性->构建) 步骤5:更新SwaggerConfig.cs以包含XmlComments。
步骤6:向控制器添加XML注释。
WebApplication1.xml也会在bin文件夹中生成。
但是Swagger UI没有显示注释,我不确定我在哪里出错了:
步骤1:创建一个全新的ASP.NET Web API项目。 步骤2:创建了一个Web API项目。 步骤3:安装了Swashbuckle 5.6.0 NuGet包。 步骤4:启用生成XML文档文件(项目属性->构建) 步骤5:更新SwaggerConfig.cs以包含XmlComments。
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration.EnableSwagger(c =>
{
var xmlFile = "bin\\" + $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
}
步骤6:向控制器添加XML注释。
///<Summary>
/// Get these comments1
///</Summary>
public class ValuesController : ApiController
{
///<Summary>
/// Get these comments2
///</Summary>
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
WebApplication1.xml也会在bin文件夹中生成。
<?xml version="1.0"?>
<doc>
<assembly>
<name>WebApplication1</name>
</assembly>
<members>
<member name="T:WebApplication1.Controllers.ValuesController">
<Summary>
Get these comments1
</Summary>
</member>
<member name="M:WebApplication1.Controllers.ValuesController.Get">
<Summary>
Get these comments2
</Summary>
</member>
<member name="M:WebApplication1.Controllers.ValuesController.Get(System.Int32)">
<Summary>
Get these comments3
</Summary>
</member>
<member name="M:WebApplication1.Controllers.ValuesController.Post(System.String)">
<Summary>
Get these comments4
</Summary>
</member>
<member name="M:WebApplication1.Controllers.ValuesController.Put(System.Int32,System.String)">
<Summary>
Get these comments5
</Summary>
</member>
<member name="M:WebApplication1.Controllers.ValuesController.Delete(System.Int32)">
<Summary>
Get these comments6
</Summary>
</member>
</members>
</doc>
但是Swagger UI没有显示注释,我不确定我在哪里出错了:
![在此输入图片描述](https://istack.dev59.com/a4cav.webp)