首页 > 解决方案 > Swashbuckle - 同一端点生成多个 operationId

问题描述

在 .NET 4.8 WebApi 应用程序中,我有一个简单的控制器,例如

[Authorize]
public class AccountController : WebApiBaseController
{
    [AllowAnonymous]
    [HttpPost]
    public async Task<IHttpActionResult> RequestPasswordReset([FromUri]string email)
    {
        await RequestPasswordReset(email);
        return Ok();
    }
}

当我使用 swashbuckle 生成 api 规范时,它会为此创建多个操作。

 "/api/Account/RequestPasswordReset": {
  "post": {
    "tags": [ "Account" ],
    "operationId": "Account_RequestPasswordReset",
    "consumes": [],
    "produces": [ "application/json", "text/json", "application/xml", "text/xml" ],
    "parameters": [
      {
        "name": "email",
        "in": "query",
        "required": true,
        "type": "string"
      }
    ],
    "responses": {
      "200": {
        "description": "OK",
        "schema": { "type": "object" }
      }
    }
  }
},

但然后在我的规格中降低

 "/api/Account": {    
  "post": {
    "tags": [ "Account" ],
    "operationId": "Account_RequestPasswordReset",
    "consumes": [],
    "produces": [ "application/json", "text/json", "application/xml", "text/xml" ],
    "parameters": [
      {
        "name": "email",
        "in": "query",
        "required": true,
        "type": "string"
      }
    ],
    "responses": {
      "200": {
        "description": "OK",
        "schema": { "type": "object" }
      }
    }
  }
},

如何使它不为同一个端点生成 2 个操作?

标签: c#.netswashbucklewebapi

解决方案


推荐阅读