Swagger (swashbuckle) 中查询参数的示例值(占位符)

Fil*_*991 2 xml parameters swagger swashbuckle asp.net-core

我在 net core 中使用 swashbuckle 创建一个 swagger 记录的 API。

我的函数使用查询参数。我想在输入参数值的文本框旁边为每个查询参数添加简短描述。我通过使用 XML 注释实现了这一点:

/// <param name="propertyId">The integration property ID. Events related to presentations related to this ID will be returned</param>
public ActionResult GetEvents([BindRequired] string propertyId){}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但它还在文本框占位符中添加了描述文本: 在此输入图像描述

我发现如果生成的 JSON 具有查询参数的“示例”值,则可以更改占位符。如何添加示例值,或者如何使用 XML 注释或类似内容更改占位符?

Yiy*_*You 5

您可以尝试添加example="xxx"<param></param>添加示例值并更改占位符。

  /// <param name="propertyId" example="id">The integration property ID. Events related to presentations related to this ID will be returned</param>
        public IActionResult GetEvents([BindRequired] string propertyId) {
            ...
        }
Run Code Online (Sandbox Code Playgroud)

结果: 在此输入图像描述