Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing api has duplicate signature operations azure web api

I am trying to import my swagger schema to azure APIM but it keeps giving me duplicate signature error.

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}'`

I have double-checked my API routes and swagger schema but can't see any duplications. This schema update was working fine before May 11, 2018 azure api updates.

I have read the release notes but couldn't find anything. My endpoints look like this.

    [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)
like image 489
yakhtarali Avatar asked Oct 26 '25 17:10

yakhtarali


1 Answers

I have fixed this issue by reading the Path template validation changes part from the Release notes. As it states to 'improve deduplication logic' they have added normalization steps prior to checking for uniqueness:

If the path template contains a query string, all segments after ? delimited with & character are sorted in alphabetical, case-insensitive order (without any special handling for = character).

That means if you have two endpoints like bellow

    [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)

this APIM will check for uniqueness by converting them into like:

"brokers/{brokerId:int:min(1)}" to "brokers/{0}" and "brokers/{webUrl}" to "brokers/{0}"

and will give a duplicate signature error.

Both endpoints are being used in mobile apps so I had no option to alter the routes, so I merged by both endpoints to

    [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;
        }
like image 160
yakhtarali Avatar answered Oct 28 '25 08:10

yakhtarali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!