如何在 Swagger .json 文件中包含ControllerXmlComments?

问题描述 投票:0回答:1

对于我的 .net core 8.0 api 项目,我使用 Swashbuckle.AspNetCore 6.5.0 到

.AddSwaggerGen()
,它在 http://localhost:5229/swagger/my_api_name/swagger.json 生成并提供 .json 文件可以浏览http://localhost:5229/swagger/index.html。

我想将控制器操作

///<summary>
评论作为终点下的摘要。

但是,我在 Swashbuckle Github 存储库 中看到的唯一方法是包含正在使用的控制器 xmldocs

public static void IncludeXmlComments(
            this SwaggerGenOptions swaggerGenOptions,
            string filePath,
            bool includeControllerXmlComments = false)

我不想生成 XML 文件,如何在生成的 .json 文件中包含 xmldoc 注释?

.net-core swagger swashbuckle swashbuckle.aspnetcore
1个回答
0
投票

我想将控制器操作

///<summary>
注释作为总结包含在终点下。

如果不使用 C# 编译器生成的 Xml 文档,这是不可能的。

开始使用 Swashbuckle 和 ASP.NET Core

一些 Swagger 功能(例如,输入参数的架构或 HTTP 方法和来自相应属性的响应代码)有效 无需使用 XML 文档文件。 对于大多数功能, 即方法摘要和参数说明以及 响应代码,必须使用 XML 文件。

从上面来看,您将必须使用 C# 编译器来生成 xml 文档文件(为了让

Swashbuckle
从生成的 xml 文档中获取
<summary>
元素中的端点描述),这是一个轻松的过程。

只需在 .csproj 中启用

GenerateDocumentationFile
并配置 Swagger 来读取生成的文件。

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