basePath parameter to the tsoa spec-and-routes command isn't used in the routes generation
See original GitHub issueWhenever using the spec-and-routes command and passing the --basePath argument the value is correctly considered in the spec generation but not in the routes generation
Sorting
-
I’m submitting a …
- bug report
- feature request
- support request
-
I confirm that I
- used the search to make sure that a similar issue hasn’t already been submit
Expected Behavior
The routes generated should be prefixed by the basePath
tsoa spec-and-routes --basePath /api/test
"servers": [
{
"url": "/api/test"
}
]
app.post('/api/test/call',
Current Behavior
tsoa spec-and-routes --basePath /api/test
The basePath is only considered for the specGeneration
"servers": [
{
"url": "/api/test"
}
]
app.post('/call',
Possible Solution
Also add the args.basePath to the config.routes.basePath value in https://github.com/lukeautry/tsoa/blob/d016cfc2d1d5a200777c9c715d7e894b2c6b2de3/packages/cli/src/cli.ts#L343
Steps to Reproduce
Having a base tsoa project just run
tsoa spec-and-routes --basePath /api/test
and check that the routes haven’t been correctly prefixed
Context (Environment)
Version of the library: 3.9.0 Version of NodeJS: 15.14.0
- Confirm you were using yarn not npm: [x]
Detailed Description
On the generateSpecAndRoutes method of the cli https://github.com/lukeautry/tsoa/blob/d016cfc2d1d5a200777c9c715d7e894b2c6b2de3/packages/cli/src/cli.ts#L339
the basePath arg should also be added to the routes config, like so:
if (args.basePath) {
config.spec.basePath = args.basePath;
config.routes.basePath = args.basePath;
}
Breaking change?
Yes it is, even though that’s some strange behaviour it might have gone unnoticed for some people and by fixing it their routes will stop working
Temporary workaround
I’m justing using the route and spec generation commands separately
tsoa routes --basePath /api/${npm_package_name#*/} && tsoa spec --basePath /api/${npm_package_name#*/}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6
Top GitHub Comments
@WoH I’m happy to provide a PR for this, the fix looks really simple. Is there anything I should be aware of?
This is a problem for me as well. I also found this happens if you specify basePath in tsoa.json instead of on the command-line even if you run the routes and spec generation separately. Only way to get around it is running the routes and spec commands with the basePath on the command-line.