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

时间:2017-02-03 07:23:50

标签: asp.net-web-api2 swagger swagger-ui

当我通过Swagger启用此文档功能时,我能够查看有关我的文档的所有类型的信息,但没有关于我的控制器名称详细信息/说明的详细信息。

如何显示控制器文档内容,如下例所示?

/// <summary> 

/// Represents the alert api controller class.

/// <summary>

public class XYZController : ApiController
{

}

在启用招摇时,我无法在Represents the XYZ api controller class. here

的任何地方看到此内容

但是我能看到我的所有方法描述。

7 个答案:

答案 0 :(得分:3)

SwaggerConfig类中是否有以下代码?

GlobalConfiguration.Configuration 
            .EnableSwagger(c =>
                {

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

答案 1 :(得分:2)

我认为这与以下问题有关: 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.

答案 2 :(得分:1)

您需要在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

答案 3 :(得分:1)

这是可能的,请参阅此页面上的@Liversage答案https://github.com/domaindrivendev/Swashbuckle/issues/572

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

答案 4 :(得分:1)

就我而言,我只需要标记即可使用XML文档 enter image description here

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

答案 5 :(得分:1)

上面的一些人已经回答了,我想问题是关于这个的:

[
    0 => 'foo1', 
    1 => 'foo2'
];

设置var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); s.IncludeXmlComments(xmlPath, includeControllerXmlComments: true); 将允许获取控制器摘要。

答案 6 :(得分:0)

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);

有关更多详细信息,请转到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);

有关更多详细信息,请转到https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-5.0&tabs=visual-studio