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

Support string variable in the first argument of @Extension #1520

Open
3 of 4 tasks
tszshingt opened this issue Dec 8, 2023 · 1 comment
Open
3 of 4 tasks

Support string variable in the first argument of @Extension #1520

tszshingt opened this issue Dec 8, 2023 · 1 comment
Labels
good first issue This issue could be an easy PR for those looking to help contribute help wanted

Comments

@tszshingt
Copy link

If I use a string variable in the first argument of @Extension:

const MY_EXTENSION = "x-extension";
@Extension(MY_EXTENSION, "first extension")

it throws the following error:

Error: The first argument of @Extension must be a string

I have tried the followings but none of them worked:

const MY_EXTENSION = "x-extension" as const;
@Extension(MY_EXTENSION, "first extension")

const MY_EXTENSION : "x-extension" = "x-extension";
@Extension(MY_EXTENSION, "first extension")

Currently, the only way to set the key is to use a string literal:

@Extension("x-extension", "first extension")

I am going to be using the key x-extension in many API endpoints, so it would be nice to be able to declare a constant as the key to reduce errors.

Is there a workaround to pass in string variable as the first argument of @Extension?

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

We should be able to pass in a string variable like in other decorators.

Current Behavior

It throws an error when I pass in a string variable as the first argument of @Extension.

Possible Solution

The error is thrown from this line of code: https://github.com/lukeautry/tsoa/blob/8b30ec76a2ea460553a26a511317e918bc503da6/packages/cli/src/metadataGeneration/extension.ts#L16C1-L16C1

It is currently checking the argument using ts.isStringLiteral(). Could we just simply check if it is a string instead of String Literal?

Steps to Reproduce

See description above.

Context (Environment)

Version of the library: 3.14.1
Version of NodeJS: 16.20.2

  • Confirm you were using yarn not npm: [ ] We are using rush

Detailed Description

See description above.

Breaking change?

Not sure. String is a superset of String Literal, so it should not break existing functionalities, but not sure if String Literal was required for any reason.

Copy link

github-actions bot commented Dec 8, 2023

Hello there tszshingt 👋

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

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

@WoH WoH added help wanted good first issue This issue could be an easy PR for those looking to help contribute labels Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue could be an easy PR for those looking to help contribute help wanted
Projects
None yet
Development

No branches or pull requests

2 participants