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

问题描述 投票:3回答:3

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

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

/// <summary> 

/// Represents the alert api controller class.

/// <summary>

public class XYZController : ApiController
{

}

在启用招摇时,我无法在Represents the XYZ api controller class. here的任何地方看到这个内容

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

asp.net-web-api2 swagger swagger-ui
3个回答
3
投票

SwaggerConfig类中是否有以下代码?

GlobalConfiguration.Configuration 
            .EnableSwagger(c =>
                {

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

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.


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

© www.soinside.com 2019 - 2024. All rights reserved.