-
Notifications
You must be signed in to change notification settings - Fork 504
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
Escape backtick and template variable from type name #1469
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello there MacFJA 👋
Thank you and congrats 🎉 for opening your first PR on this project.✨
We will review the following PR soon! 👀
Looks reasonable, can you please add the example you provided as a test? |
@WoH Sorry for the delay. |
@@ -770,9 +770,11 @@ export class TypeResolver { | |||
.replace(/,/g, '.') | |||
.replace(/'([^']*)'/g, '$1') | |||
.replace(/"([^"]*)"/g, '$1') | |||
.replace(/`([^`]*)`/g, '$1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This concern is valid for both this and the other escape, but I think we can construct scenarios where this could lead to a clash (2 different references ending up with the same name), right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it could, and whenever char are replaced or removed.
l TS Type | Escaped value | Data group |
---|---|---|
Omit<MyType, "_foo"> |
Omit_MyType._foo_ |
The type MyType minus the key _foo (1) |
Omit<MyType, '_foo'> |
Omit_MyType._foo_ |
The type MyType minus the key _foo (1) |
Omit<MyType, `_foo`> |
Omit_MyType._foo_ |
The type MyType minus the key _foo (1) |
Omit<MyType, `${foo}`> |
Omit_MyType._foo_ |
The type MyType minus the key of type foo (2) |
Omit<MyType, `${fo}o`> |
Omit_MyType._foo_ |
The type MyType minus the key of (type fo + text o ) (3) |
Omit<MyType, `${"foo"}`> |
Omit_MyType._foo_ |
The type MyType minus the key foo (4) |
many more possibilities |
For the first 3, they are the same data, so it's not a big deal.
There is maybe another case (I don't tested it yet): classes, interfaces, types, enums are not "unique".
In TSOA, refType
don't mention their source file, so:
// fileA.ts
import { MyType } from "./somewhere/in/the/project"
// fileB.ts
import { MyType } from "./in/another/place"
will be declared as the same schema in the OpenAPI file (to be confirmed), and so create a clash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's possible that's a bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we find a way to rewrite that so it does not clash with other, but different type names?
Is the PR merged to version 5.1.1? |
Would you like to improve on this PR and address the points I raised during review? Remember to add tests. |
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 |
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 |
All Submissions:
This PR solve the issue with Swagger that can't handle
$
schema name.My use case is the following:
TSOA can't use the type
MyModal
which is understandable as one of the key is dynamic.My approach what to create a TSOA specific type like this:
With this, TSOA is able to generate the OpenApi file,
but the generated schemas are:
With my PR the output will be: