lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.45k stars 494 forks source link

MetadataGenerator.checkForMethodSignatureDuplicates is not working properly #1482

Closed pauline-greenly closed 8 months ago

pauline-greenly commented 11 months ago

Sorting

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:

Detailed Description

Breaking change?

github-actions[bot] commented 11 months ago

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 commented 8 months ago

@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.