1

I'm trying to apply api management version sets to query a .Netcore 3.1 web api which has two versions. I have chosen the path schema on the version set, which appends the version identifier to the url. In this case /v1: enter image description here

The thing is that in my api I am also using path schema to version the endpoint on the web api, so when apim builds the url, it appends the apim version identifier to the api version path, which results in a duplicate, like:

https://myapi.com/apiname/v1/v1/endpoint , where v1/endopoint is the path to the controller.

To solve this, I have switched the version schema on the web api to header and created a policy on apim that adds the version header to the request, so that the only version in the path is now the one in apim.

I wanted to know if this is the right way to go or if there is a better solution. Maybe its possible to tell apim to ignore the version /v1 from the path?

Thanks for the help!

Rui Vaz
  • 55
  • 1
  • 6

1 Answers1

1

APIMs domain model allows one to control versioning scheme (path prefix, header name/value, query parameter name/value) at the level of API version set, so that you do not need to duplicate /v1.0 on every operation of your API. By nature of this if your API version set is configured to have path prefix of /v1.0 it will be appended to all API paths included into this version set. And that is what produces the doubling.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • while i appretiate the explanation, I don't understand what you are trying to say. do you mean that i dont have to set the path version routes in my api? – Rui Vaz Aug 07 '20 at 13:20
  • 1
    You can check out this blog post, which describes this approach. https://www.hakantuncer.com/2018/09/16/api-versioning-with-swagger-azure-api-management-services-and-asp-net-core-a-frictionless-devops-experience/ – Jean-Paul Smit Aug 07 '20 at 20:46
  • Any update now? If it helps you , please accept it as answer. – Joey Cai Aug 13 '20 at 06:24
  • Hi Joey. Thank you for the help, but, unfortunately but it wasn't helpful. Possibly because the problem is related to the way swashbuckle is generating the open api routes. the version path is added to the openapi route specifications and apim imports this into the versioned set, meaning it will contain the /v1/ path from the versionset in apim, and the /v1/ path from the open api routes. There should be an option to omit this version path in the swagger gen configuration but i cant find it. – Rui Vaz Aug 17 '20 at 16:16
  • 1
    @RuiVaz from what I can tell, this would actually work. If you look at the associated PowerShell script, it is using some regular expressions and other manipulation to fix-up the paths. This is more of a problem with APIM imposing its will on you than anything else. Another alternative would be to use the API Explore and, optionally, the Swashbuckle CLI to generate the documents differently. It's pretty easy to inject a process that would remove the first segment for APIM – Chris Martinez Sep 16 '20 at 20:04
  • Hi @ChrisMartinez. I see what you mean. Using this powershell script to import the api might work. I will have to consider that option though since we are using terraform provisioning and adding a ps script into the mix will add more complexity. I might try to use the swashbuckle cli to accomplish this. I have opened a ticket in their repo to see how that is possible, but i still havent received a response. Thanks for the feedback! – Rui Vaz Sep 24 '20 at 12:01
  • 1
    Any news about this? I'm having this problem too. – Jackson Mourão Oct 22 '20 at 13:36