Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetadataGenerator.checkForMethodSignatureDuplicates is not working properly #1482

Closed
2 of 4 tasks
pauline-greenly opened this issue Sep 19, 2023 · 2 comments
Closed
2 of 4 tasks

Comments

@pauline-greenly
Copy link

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

When generating two differents apis, with differentiate docs, where the base paths are "api/v1" and "api/v2".
TSOA should allow to generates two sames routes with two different base path. 
Example: 
POST /api/v1/users
POST /api/v2/users

Those two routes should work

Current Behavior

The generation of the routes does not work when the route are identical but not the base path.

Error :

Generate routes error.
 GenerateMetadataError: Duplicate method signature @post(suppliers) found in controllers: SupplierController#bulkImport, SupplierController#bulkImport

    at MetadataGenerator.checkForMethodSignatureDuplicates (/Users/paulinegangloff/Documents/offspend/node_modules/@tsoa/cli/dist/metadataGeneration/metadataGenerator.js:41:23)
    at MetadataGenerator.Generate (/Users/paulinegangloff/Documents/offspend/node_modules/@tsoa/cli/dist/metadataGeneration/metadataGenerator.js:138:14)
    at generateRoutes (/Users/paulinegangloff/Documents/offspend/node_modules/@tsoa/cli/dist/module/generate-routes.js:14:177)
    at routeGenerator (/Users/paulinegangloff/Documents/offspend/node_modules/@tsoa/cli/dist/cli.js:261:52

Possible Solution

This line should take into account also the base path

const signature = method.path ? `@${method.method}(${controller.path}/${method.path})` : `@${method.method}(${controller.path})`;

Steps to Reproduce

  1. Create two identical controller, 1 in a v1 directory, the other in a v2 directory
  2. Reproduce with this kind of command:
tsoa routes --basePath api/v1 --configuration src/presentation/rest-api/v1/tsoa.json
tsoa routes --basePath api/v2 --configuration src/presentation/rest-api/v2/tsoa.json

Context (Environment)

Version of the library:
Version of NodeJS:

  • Confirm you were using yarn not npm: [x]

Detailed Description

Breaking change?

@github-actions
Copy link

Hello there pauline-greenly 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

@jackey8616
Copy link
Collaborator

@pauline-greenly tsoa can not recognize controller's base path by its folder name, thus the Generator can not process as you wish.

Once you execute the tsoa routes command, tsoa would take whole folder(including v1 and v2 folrder) to generate routes.

@WoH:
I think this is not a bug, since the issue author's usecase is slightly different to the usual way using tsoa.
We should provide some sort of decorator to mark controller's base path to do such things.

@WoH WoH closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants