当我通过 Swagger 启用此文档功能时,我可以查看有关我的文档的所有类型的信息,但没有关于我的 Controller 名称详细信息/描述的详细信息。
如何显示 Controller 文档内容如下例所示?
/// <summary>
/// Represents the alert api controller class.
/// <summary>
public class XYZController : ApiController
{
}
在启用 swagger 时,我无法在任何地方看到此内容
Represents the XYZ api controller class. here
但是我能够看到我的所有方法描述。
最佳答案
您需要在 AddSwaggerGen 中添加 IncludeXmlComments 扩展,如下所示:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1.0", new Info
{
Title = "My APIs",
Version = "v1.0",
Description = "REST APIs "
});
**// Set the comments path for the Swagger JSON and UI.**
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
For more details refer here
关于asp.net-web-api2 - Swagger 文档中未显示 WebApi Controller 摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42018857/