-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[TypeScript-Consolidated] Fixes invalid type enum array & incorrect discriminator value if mapping is present #15272
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
base: master
Are you sure you want to change the base?
Conversation
@@ -293,6 +293,40 @@ public String toEnumValue(String value, String datatype) { | |||
} | |||
} | |||
|
|||
/** |
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.
TODO: Extract to AbstractTSClientCodegen
* In these cases, we then have Array <{ [key: EnumName]: EnumName}> - which is invalid typescript | ||
* To protect agains this we first replace [key: string] with a special/reserved placeholder (i.e. *[key]* ) | ||
*/ | ||
property.datatypeWithEnum = property.datatypeWithEnum.replace("[key: string]", "*key*") |
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.
*key*
can be constant with PLACEHOLDER name.
#PLACEHOLDER# or something else.
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.
Actually using regular expression with replaceAll might help avoiding placeholder. We always looking to replace last occurence
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.
Is it always the last occurrence?
Wondering whether there are more complicated examples where this does not hold - mainly thinking about cases where the same type appears twice (e.g., Tuple<string, string>
to Tuple<FancyEnum, FancyEnum>
).
In cases like this, our model is anyway broken because we lose type information when generating the initial type.
Precompiled. It does solve the issue with array. |
Technical committee: Would appreciate your review/input :) @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka |
Sounds like maybe a unit test makes sense here!? I would definitely prefer a proper fix when generating the type instead of a workaround with string replacements. |
Agreed, let me add some unit test. If I remember well (few weeks ago when I worked on this), I initially tried going for a proper fix but discovered that the function where the initial type is set does not have the full context necessary to set the right type from the start |
See #14892
Still WIP - will expand on description once ready.
@wtrocki Code now compiles for the spec that you had posted; Will have CI run the tests against the existing specs in OpenAPI Generator to see whether I broke anything else.
CC Technical Committee
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)