代码之家  ›  专栏  ›  技术社区  ›  yakhtarali Daniel Sloof

导入API具有重复的签名操作Azure Web API

  •  0
  • yakhtarali Daniel Sloof  · 技术社区  · 8 年前

    我正在尝试将我的Swagger架构导入到Azure APIM,但它一直给我重复的签名错误。

    Importing API has duplicate signature operations: 2 operations with signature 'GET /api/v1/brokers/{brokerid}'; 2 operations with signature 'GET /api/v1/marketreport/{brokerid}'; 2 operations with signature 'GET /api/v1/offices/{officeid}'; 2 operations with signature 'GET /api/v1/teams/{teamid}'

    我已经仔细检查了我的API路由和Swagger模式,但没有发现任何重复。此架构更新在2018年5月11日之前运行良好。

    我读过 release notes 但找不到任何东西。我的端点看起来像这样。

    [Route("{officeId:int:min(1)}", Name = "GetOfficeById")]
    public IHttpActionResult GetOfficeById(int officeId, [FromUri] IncludeImageModel includeImage)
    
    [Route("{brokerId:int:min(1)}", Name = "GetBrokerById")]
    public IHttpActionResult GetBrokerById(int brokerId, [FromUri] IncludeImageModel includeImage)
    
    [Route("{teamId:int:min(1)}", Name = "GetTeamById")]
    public IHttpActionResult GetTeamById(int teamId, [FromUri] IncludeImageModel includeImage)
    
    [Route("MarketReport/{brokerId:int}", Name = "GetMarketReportsByBrokerId")]
    public IHttpActionResult GetMarketReportsByBrokerId(int brokerId, [FromUri]CBBainApi.Models.Common common)
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   yakhtarali Daniel Sloof    8 年前

    我通过阅读 Path template validation changes 部分来自 Release notes . 在IT部门统计“改进重复数据消除逻辑”时,他们在检查唯一性之前添加了规范化步骤:

    如果路径模板包含查询字符串,那么之后的所有段?用&字符分隔的按字母顺序排序,不区分大小写(不需要对=字符进行任何特殊处理)。

    这意味着如果你有两个端点,像下面这样

    [RoutePrefix("brokers")]
    public class BrokerController : ApiController
    
    [HttpGet]
    [Route("{brokerId:int:min(1)}", Name = "GetBrokerById")]
    public IHttpActionResult GetBrokerById(int brokerId, [FromUri] IncludeImageModel includeImage)
    
    [HttpGet]
    [Route("{webUrl}", Name = "GetBrokerByWebUrl")]
    public IHttpActionResult GetBrokerByWebUrl(string webUrl, [FromUri] IncludeImageModel includeImage)
    

    此APIM将通过将其转换为以下内容来检查其唯一性:

    "brokers/{brokerId:int:min(1)}" 到 "brokers/{0}" 和

    "brokers/{webUrl}" 到 “经纪人/0”

    并会给出重复的签名错误。

    我的两个端点都在移动应用程序中使用,所以我没有选择改变路径。 所以我把两个端点合并到

    [HttpGet]
    [Route("{param}", Name = "GetBroker")]
    public IHttpActionResult GetBroker(string param, [FromUri] IncludeImageModel includeImage)
          {
             int brokerId = default(int);
             if (int.TryParse(param, out brokerId))
                 ... do something
             else
                 ...do something else
            //return something;
        }