asp.net-web-api2 - Swagger 文档中未显示 WebApi Controller 摘要

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

当我通过 Swagger 启用此文档功能时,我可以查看有关我的文档的所有类型的信息,但没有关于我的 Controller 名称详细信息/描述的详细信息。

如何显示 Controller 文档内容如下例所示?

/// <summary> 

/// Represents the alert api controller class.

/// <summary>

public class XYZController : ApiController
{

}

在启用 swagger 时,我无法在任何地方看到此内容 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);            
        });

For more details refer here

关于asp.net-web-api2 - Swagger 文档中未显示 WebApi Controller 摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42018857/

相关文章:

java - 如何拒绝访问嵌入式 tomcat 容器中的某些路由

java - 如何在 Java swagger UI 中将对象数组作为参数传递?

c# - 使用 Web API Controller 解析传入的 JSON(来自 javascript Ajax post)

asp.net - 如何在 .net WebApi2 应用程序中使用 OAuth2 token 请求中的额外参数

asp.net-core - Swashbuckle aspnet core 2.0 Swaggerconfig.cs 未创建

c# - 具有相同动词和不同路由的 Azure API App 多个操作会产生 swagger 错误

rest - 将 Swagger UI 嵌入 Blazor 服务器端应用程序

javascript - 使用 Ajax 调用 Web Api 2 方法

asp.net-mvc-4 - Web API 2 返回 OK 响应但继续在后台处理

Swagger: "equivalent path already exists"尽管参数不同