简体   繁体   English

Swagger 文档中未显示 WebApi 控制器摘要

[英]WebApi controller summary is not showing on Swagger documentation

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.当我通过 Swagger 启用此文档功能时,我能够查看有关我的文档的所有类型的信息,但没有关于我的控制器名称详细信息/描述的详细信息。

How to show controller documentation content like below example?如何显示控制器文档内容如下例所示?

/// <summary> 

/// Represents the alert api controller class.

/// <summary>

public class XYZController : ApiController
{

}

On enabling swagger I'm not able to see this content any where Represents the XYZ api controller class. here在启用 swagger 时,我无法在任何Represents the XYZ api controller class. here地方看到此内容Represents the XYZ api controller class. here Represents the XYZ api controller class. here

However I able to see my all method description.但是我能够看到我的所有方法描述。

you need to add IncludeXmlComments extension in AddSwaggerGen as below:您需要在 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 有关更多详细信息,请参阅此处

1.) Right click the project and Edit projname.csproj Add the following 1.) 右键单击​​项目并编辑 projname.csproj 添加以下内容

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

2.) Add the following to AddSwaggerGen in ConfigureServices 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);

For more details goto:有关更多详细信息,请转到:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-5.0&tabs=visual-studio https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-5.0&tabs=visual-studio

Is there following code in the SwaggerConfig class? SwaggerConfig 类中是否有以下代码?

GlobalConfiguration.Configuration 
            .EnableSwagger(c =>
                {

                    c.IncludeXmlComments(string.Format(@"{0}\bin\YourAssemlyName.XML", System.AppDomain.CurrentDomain.BaseDirectory));  

This is possible, See @Liversage answer on this page https://github.com/domaindrivendev/Swashbuckle/issues/572这是可能的,请参阅此页面上的@Liversage 答案https://github.com/domaindrivendev/Swashbuckle/issues/572

services.AddSwaggerGen(c =>
{
    var xmlPath = ...;
    c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
});

As some guys above have reply already, I guess the question was about this:由于上面的一些人已经回复了,我想问题是关于这个的:

var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
s.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);

set includeControllerXmlComments: true will allow to take summary of controllers. set includeControllerXmlComments: true将允许对控制器进行汇总。

I think this is related to the following issue : https://github.com/domaindrivendev/Swashbuckle/issues/572我认为这与以下问题有关: https : //github.com/domaindrivendev/Swashbuckle/issues/572

It is currently not possible to display the controller summary, according to the maintainer:根据维护者的说法,目前无法显示控制器摘要:

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.

in my case, I only needed to mark to use the XML document就我而言,我只需要标记即可使用 XML 文档在此处输入图片说明

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>C:...\CertReports.Host.xml</DocumentationFile>

现在,在 .net core 中很容易

config.UseControllerSummaryAsTagDescription = true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM