Swashbuckle.WebApi
Swashbuckle.WebApi copied to clipboard
customize api paths in swagger to remove controller version path
Hi all, I am attempting to use APIM version sets with path route. I import the the api using terraform provisioning, which reads the openapi document to generate the endpoints. The problem that i encounter is that since my api already uses path version, this path is appended to the apim path version and results in a duplicate path version, ex. v1/v1/endpoint This works as intended since swagger reads the v1 path from the controller route to generate the document. However this is not desired, since apim already has the v1 path in the version set.
I wanted to know if its possible to customize these routes so that i can remove the path from the openapi document, while keeping the actual path in the controller route.
VERSION:
5.5.1
STEPS TO REPRODUCE:
on startup add api versioning to your services services.AddApiVersioning();
decorate your endpoint with [Microsoft.AspNetCore.Mvc.Apiversion("1.0")] and [Route("v1/[controller]")]
EXPECTED RESULT:
This is not so much the expected result as the desired result: paths": { "/controllerName": {
}
ACTUAL RESULT:
in the paths of the open api document you see the route: paths": { "v1/controllerName": {
}
This will not work as defined. You cannot use a literal v1. When versioning by URL segment, you need to use the route constraint v{version:apiVersion}. It looks like you are using ASP.NET Core, but this repo is for Web API. The main issue has more to do with what APIM is doing than anything else. If possible, consider using the query string instead.
Ultimately, it looks like you already found your answer and workable solution: https://stackoverflow.com/questions/63263394/azure-api-management-versioning-path-schema-duplicates-version-in-url