question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

basePath parameter to the tsoa spec-and-routes command isn't used in the routes generation

See original GitHub issue

Whenever 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
sl33krcommented, Jul 27, 2022

@WoH I’m happy to provide a PR for this, the fix looks really simple. Is there anything I should be aware of?

1reaction
gregbonney-rgarecommented, Oct 7, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generating Routes and OAS | tsoa - GitHub Pages
Usage: tsoa routes [options] Options: --configuration, -c tsoa configuration file; default is tsoa.json in the working directory [string] --basePath Base ...
Read more >
tsoa - Bountysource
If I use aliases when importing tsoa types, routes aren't generated for controller methods annotated with those types. For example, the following controller ......
Read more >
Routing — Connexion 3.0.dev0 documentation
paths : /hello_world: post: x-swagger-router-controller: myapp.api operationId: hello_world. NOTE: If you are using an OpenAPI spec, you should use ...
Read more >
Tsoa/Typescript hanging when generating spec and routes
After working for a while where everything was working great, the tsoa spec-and-routes command all of a sudden got stuck.
Read more >
Rewrites - next.config.js
Rewrites are applied to client-side routing, a <Link href="/about"> will have ... The :path parameter isn't used here so will be automatically passed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found