kumar
kumar

Reputation: 9387

version appearing twice in url when using versioned api with Azure API Managment

I am integrated my versioned APIs with swagger and with Azure API Management. The version number comes twice once I import the swagger definition API Management. Is there a better way we could do this with swagger or with API managment so that second V1 does not appear?

API ManagmentURL https://my-apimgnt.azure-api.net/myapi-dev/v1/api/v1/user/Skills/get

Direct URL/backend https://jsdevsf.api.mydomain.com/api/v1/user/Skills

[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/user/[controller]")]
[ApiController]

Swagger Definition

{
"swagger": "2.0",
"info": {
"version": "2.0",
"title": "MyAPI 2.0",
"termsOfService": "None",
"contact": {
"name": "mySupport",
"email": "[email protected]"
}
},
"basePath": "/my.Application/my.WebAPI",
"paths": {

    "/api/v1/user/Skills/get/{ProductId}": {}
}

Upvotes: 2

Views: 559

Answers (1)

Architect Jamie
Architect Jamie

Reputation: 2569

Paths are relative to the basePath or Base URI.

Looks like you just need to remove the /api/v1 part from your swagger definition. So your definition should be:

{
"swagger": "2.0",
"info": {
"version": "2.0",
"title": "MyAPI 2.0",
"termsOfService": "None",
"contact": {
"name": "mySupport",
"email": "[email protected]"
}
},
"basePath": "/my.Application/my.WebAPI",
"paths": {

    "/user/Skills/get/{ProductId}": {}
}

To do this from Azure, go to Design -> Front End -> OpenAPI Specification Editor

From here you should see basePath and paths. Swagger Editor should also display and allow you to configure these values.

Upvotes: 1

Related Questions