将 WebApi 方法的参数标记为 Swashbuckle / Swagger 已过时/已弃用

Jon*_* L. 8 c# swashbuckle webapi

根据我对Swagger 规范的理解,可以将参数标记为过时:

不推荐使用的参数

用于deprecated: true将参数标记为已弃用。

        - in: query
          name: format
          required: true
          schema:
            type: string
            enum: [json, xml, yaml]
          deprecated: true
          description: Deprecated, use the appropriate `Accept` header instead.```
Run Code Online (Sandbox Code Playgroud)

我怎样才能让 Swashbuckle 为参数生成这个?

为什么?

我有一个类似以下的控制器方法:

        - in: query
          name: format
          required: true
          schema:
            type: string
            enum: [json, xml, yaml]
          deprecated: true
          description: Deprecated, use the appropriate `Accept` header instead.```
Run Code Online (Sandbox Code Playgroud)

我想更改查询字符串参数名称,同时暂时保持向后兼容,所以我想做类似的事情:

[HttpGet]
public async Task<IActionResult> Execute(bool? someName)
{
}
Run Code Online (Sandbox Code Playgroud)

但是,Obsolete不能应用于参数。我预计这Swashbuckle.AspNetCore.Annotations可能是一个找到这种功能的地方,但它似乎没有。

Min*_*ipe 8

您不会将参数标记为过时,如果参数过时,整个方法也会过时。您需要使用新方法签名声明一个新方法,并将旧方法标记为已过时。像这样

[HttpGet]
[Obsolete("Use Execute with bool? someNewName instead.")]
public async Task<IActionResult> Execute(bool? someName)
{
}

[HttpGet]
public async Task<IActionResult> Execute(bool? someNewName)
{
}
Run Code Online (Sandbox Code Playgroud)

如果您只更改了参数的名称,则可以使用该Bind属性将 URI 元素绑定到不同名称的变量,如下所示:

[HttpGet]
public async Task<IActionResult> Execute([Bind(Prefix = "someNewName")] bool? someName)
{
}
Run Code Online (Sandbox Code Playgroud)

这将允许您继续使用相同的方法,而不必强制更改所有客户端。但是,如果不仅仅是参数名称发生变化,例如类型,您将需要一个新方法