对于多个 HTTP 方法具有相同的控制器代码,是否可以从 Swagger UI 中仅隐藏其中一个?

Having the same controller code for multiple HTTP methods, is it possible to hide only one of them from Swagger UI?

相同的方法和相同的路由用于两个不同的端点:一个是GET,另一个是POST。有没有办法从 Swagger UI?

中仅隐藏其中一个(例如,仅 GET 一个)
[Route("myroute")]
[HttpPost]
[HttpGet] // This is being keep for compatibility purposes (legacy services that are still using it)

我尝试使用 IgnoreApi 属性(见下文)但没有成功:它隐藏了 GET 和 POST。似乎它隐藏了整个路由,无论 HTTP 方法如何。

[ApiExplorerSettings(IgnoreApi = false)]

不在同一个端点上。 ApiExplorerSettings 属性适用于整个方法,不能应用于方法附带的特定属性。

您可以做的是:

[HttpPost]
public void MyCurrentMethod() {
    //Do stuff...
}

[ApiExplorerSettings(IgnoreApi = true)]
[HttpGet]
public void MyDepricatedMethod() => MyCurrentMethod();