When generating controller paths for the Swagger/OpenAPI specification, basePath is prepended to each controllerPath, which results in duplicated basePath values in the generated Swagger paths. Example: If basePath is /api and controllerPath is also prefixed, /api might appear twice (/api/api/...).
Proposed solution:
- Refactor the code so that
options.basePath is added only once to the final generated path, and is not already included when computing controller-specific paths. Only append options.basePath to the very beginning of the final Swagger path.
Context:
File: src/openapi/OpenApi.ts
Repo: iyobo/amala
Relevant code:
const basePath = options.basePath + convertRegexpToSwagger(controllerPath);
// ... endpoint.paths.forEach ...
const fullPath = basePath + convertRegexpToSwagger((endpointPath === "/" ? "" : endpointPath));
This logic causes basePath to be added before each controller, potentially duplicating it if the controller path is already relative.
Expected:
- Swagger paths should contain
basePath only once at the beginning.
- There should be no duplicated path segments due to repeated concatenation.
Note:
I wanted to send a PR myself for this, but I am unable to because I am not sure if there are any edge cases or considerations that need to be accounted for when fixing this logic. Please review if there are aspects in path generation that require care (e.g., backwards compatibility, interaction with existing options, etc.) before applying the change.
Please update the openapi path generation logic to fix this issue.
When generating controller paths for the Swagger/OpenAPI specification, basePath is prepended to each controllerPath, which results in duplicated basePath values in the generated Swagger paths. Example: If basePath is
/apiand controllerPath is also prefixed,/apimight appear twice (/api/api/...).Proposed solution:
options.basePathis added only once to the final generated path, and is not already included when computing controller-specific paths. Only appendoptions.basePathto the very beginning of the final Swagger path.Context:
File:
src/openapi/OpenApi.tsRepo:
iyobo/amalaRelevant code:
This logic causes
basePathto be added before each controller, potentially duplicating it if the controller path is already relative.Expected:
basePathonly once at the beginning.Note:
I wanted to send a PR myself for this, but I am unable to because I am not sure if there are any edge cases or considerations that need to be accounted for when fixing this logic. Please review if there are aspects in path generation that require care (e.g., backwards compatibility, interaction with existing options, etc.) before applying the change.
Please update the openapi path generation logic to fix this issue.