[英]WebApi controller summary is not showing on Swagger documentation
当我通过 Swagger 启用此文档功能时,我能够查看有关我的文档的所有类型的信息,但没有关于我的控制器名称详细信息/描述的详细信息。
如何显示控制器文档内容如下例所示?
/// <summary>
/// Represents the alert api controller class.
/// <summary>
public class XYZController : ApiController
{
}
在启用 swagger 时,我无法在任何Represents the XYZ api controller class. here
地方看到此内容Represents the XYZ api controller class. here
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);
});
1.) 右键单击项目并编辑 projname.csproj 添加以下内容
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
2.) 在 ConfigureServices 的 AddSwaggerGen 中添加以下内容
// 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);
有关更多详细信息,请转到:
SwaggerConfig 类中是否有以下代码?
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.IncludeXmlComments(string.Format(@"{0}\bin\YourAssemlyName.XML", System.AppDomain.CurrentDomain.BaseDirectory));
这是可能的,请参阅此页面上的@Liversage 答案https://github.com/domaindrivendev/Swashbuckle/issues/572
services.AddSwaggerGen(c =>
{
var xmlPath = ...;
c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
});
由于上面的一些人已经回复了,我想问题是关于这个的:
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
s.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
set includeControllerXmlComments: true
将允许对控制器进行汇总。
我认为这与以下问题有关: https : //github.com/domaindrivendev/Swashbuckle/issues/572
根据维护者的说法,目前无法显示控制器摘要:
The reason this has been low on the priority list is because it's not something I've run into issues with. You can absolutely describe what every action in your API does using XML comments on your actions.
现在,在 .net core 中很容易
config.UseControllerSummaryAsTagDescription = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.