Swagger 文档中未显示 WebApi 控制器摘要 [英] WebApi controller summary is not showing on Swagger documentation
本文介绍了Swagger 文档中未显示 WebApi 控制器摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我通过 Swagger 启用此文档功能时,我可以查看有关我的文档的所有类型的信息,但没有关于我的控制器名称详细信息/描述的详细信息.
When I enable this documentation feature through Swagger I'm able to see all kind of information about my documentation but there is no details about my Controller name detail/description.
如何像下面的例子那样显示控制器文档内容?
How to show controller documentation content like below example?
/// <summary>
/// Represents the alert api controller class.
/// <summary>
public class XYZController : ApiController
{
}
在启用 swagger 时,我无法在 代表 XYZ api 控制器类的任何地方看到此内容.这里
On enabling swagger I'm not able to see this content any where Represents the XYZ api controller class. here
但是我能够看到我的所有方法描述.
However I able to see my all method description.
推荐答案
你需要在 AddSwaggerGen 中添加 IncludeXmlComments 扩展如下:
you need to add IncludeXmlComments extension in AddSwaggerGen as below:
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);
});
这篇关于Swagger 文档中未显示 WebApi 控制器摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文