Skip to content

Test renamed imports#870

Open
MatthiasKunnen wants to merge 2 commits into
lukeautry:masterfrom
MatthiasKunnen:renamed-model-imports
Open

Test renamed imports#870
MatthiasKunnen wants to merge 2 commits into
lukeautry:masterfrom
MatthiasKunnen:renamed-model-imports

Conversation

@MatthiasKunnen

Copy link
Copy Markdown
Contributor

tsoa does not support renaming of decorators in imports nor renaming of models. This is a problem in case there is a naming conflict, for example when you have a model named Post.

The two new fixtures included in this PR contain examples of decorators such as Get being renamed and models being renamed.

Model renaming crashes the test suite outright. Method decorator renaming fails more gracefully.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions Bot added the Stale label Jan 14, 2021
@MatthiasKunnen

Copy link
Copy Markdown
Contributor Author

Not stale

@github-actions github-actions Bot removed the Stale label Jan 15, 2021
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions Bot added the Stale label Feb 15, 2021
@MatthiasKunnen

MatthiasKunnen commented Feb 15, 2021 via email

Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot removed the Stale label Feb 16, 2021
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions Bot added the Stale label Mar 18, 2021
@WoH WoH removed the Stale label Mar 18, 2021
@hasyimibhar

hasyimibhar commented Mar 30, 2021

Copy link
Copy Markdown

Is there a plan to fix this? I think it fails because tsoa checks the name of the decorator. Instead of doing that, maybe the decorator should attach a metadata to the class or method. Then tsoa can check for the presence of the metadata instead of checking for the name of the decorator. This will make it easier to integrate tsoa to existing framework which also use decorators, as you can then compose decorators.

For example, in the project I'm working on, I'm using inversify-express-utils, which allows dependencies to be injected into controller methods. But because this injected dependency will break tsoa, I have to make sure it's ignored with the @Inject decorator. So my code looks like this:

class FoobarController {
  @Post('/')
  foobar(
    // Looks ugly
    @Inject() @Inject(TYPES.User) user: User,
    @Body() req: FoobarRequest
  ) {
    // ...
  }
}

If tsoa use the metadata approach, then I can create a custom decorator in my project that calls both of these decorators, so now it can look like this:

class FoobarController {
  @Post('/')
  foobar(
    // InjectUser() is wrapper for calling both @Inject() and @Inject(TYPES.User)
    @InjectUser() user: User,
    @Body() req: FoobarRequest
  ) {
    // ...
  }
}

This will also fix the naming issue, as the user is now free to rename the decorators to anything when importing, as tsoa no longer depends on the name of the decorator.

I'm not that familiar with tsoa codebase or it this would even work (so far I only made a small PR to add the @Inject decorator), so I'm not sure if this is difficult to implement. But if it's not too difficult, and the approach makes sense, maybe I can offer a hand.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions Bot added the Stale label Apr 30, 2021
@MatthiasKunnen

MatthiasKunnen commented Apr 30, 2021 via email

Copy link
Copy Markdown
Contributor Author

@WoH

WoH commented May 13, 2021

Copy link
Copy Markdown
Collaborator

Is there a plan to fix this?

Probably not. At least I'm not aware of any easy solution.

I think it fails because tsoa checks the name of the decorator. Instead of doing that, maybe the decorator should attach a metadata to the class or method.

We can do that to make the runtime work, but we can't access that metadata when we compile the Spec

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions Bot added the Stale label Jun 13, 2021
@MatthiasKunnen

MatthiasKunnen commented Jun 13, 2021 via email

Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot removed the Stale label Jun 14, 2021
@WoH

WoH commented Jun 15, 2021

Copy link
Copy Markdown
Collaborator

No keep open option?

On Sun, Jun 13, 2021, 02:28 github-actions[bot] @.***> wrote: This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#870 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEAHNI6DO5EHC5TBRWB3RMLTSP3TXANCNFSM4U3KRSUQ .

The help wanted label should prevent that, I'll take a look and reopen manually if it happens again

@WoH WoH reopened this Jul 22, 2021
Repository owner deleted a comment from github-actions Bot Jul 22, 2021
@WoH WoH removed the Stale label Jul 22, 2021
@github-actions github-actions Bot added the Stale label Aug 22, 2021
@WoH WoH removed the Stale label Aug 23, 2021
Repository owner deleted a comment from github-actions Bot Aug 23, 2021
@WoH

WoH commented Jan 30, 2023

Copy link
Copy Markdown
Collaborator

This is now partially solved (model renaming). As for Decorators, this is not really a prio for me.

@WoH WoH force-pushed the master branch 2 times, most recently from 30cc104 to 82b61ec Compare December 8, 2024 16:44
VannaDii added a commit to tsoa-next/tsoa-next that referenced this pull request Mar 22, 2026
Implement full import alias support in
https://github.com/vannadii/tsoa-next using
lukeautry/tsoa#870 as the source reference for
broken behavior.

This branch adds support for:
- aliased imported tsoa decorators
- aliased imported referenced model/type names

The implementation uses TypeScript symbol resolution and alias
unwrapping rather than local identifier text matching.

Validation:
- `npm --workspace @tsoa-next/cli run build`
- `npm --workspace tsoa-next run build`
- `npm --workspace tsoa-tests run typecheck`
- direct `MetadataGenerator` / `SpecGenerator2` / `SpecGenerator3`
assertion script for the new aliased-import fixtures

Notes:
- The repo's Mocha workspace harness is currently failing in this
environment before test execution due workspace import resolution in the
test runner, so I validated the new fixture expectations directly
through metadata/spec generation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants