-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[JAVA][BUG] Do not use valueOf for numeric types for generating inner enums Current Master #21055
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?
[JAVA][BUG] Do not use valueOf for numeric types for generating inner enums Current Master #21055
Conversation
|
Hi @martin-mfg I've created a new PR based on the current Master. Could you please check if I've cherry picked your changes correctly? Thank you :-) |
|
This PR is great but I have seen that despite the changes added in the PR, there are still compilation errors in some case related to Object.valueOf which is wrong For example:
This problem can be solved by adding this check (isFreeFormObject) to what you have added in your PR: {{{name}}}({{^isUri}}{{^isNumeric}}{{^isFreeFormObject}}{{dataType}}.valueOf({{/isFreeFormObject}}{{/isNumeric}}{{/isUri}}{{{value}}}{{^isUri}}{{^isNumeric}}{{^isFreeFormObject}}){{/isFreeFormObject}}{{/isNumeric}}{{/isUri}}){{^-last}},@timon-sbr @martin-mfg @wing328 What do you think? |
modules/openapi-generator/src/main/resources/Java/modelInnerEnum.mustache
Outdated
Show resolved
Hide resolved
martin-mfg
left a comment
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.
Hi @jorgerod, thanks for the suggestion! Could either you (in a new PR) or @timon-sbr (in the current PR) please make the suggested changes, apply it to all relevant *.mustache files, and merge the latest master? Thanks!
@timon-sbr Do you want to make them yourself? |
…do not use valueOf factory method for BigDecimals.
…ts-models-for-testing-okhttp-gson.yaml
add00a7 to
83e7009
Compare
Hi @jorgerod sorry for the late reply. I will integrate the suggested changes in this pr and regenerate the samples. |
…um.mustache Co-authored-by: Jorge Rodríguez Martín <[email protected]>
|
Hi @martin-mfg and @jorgerod |
modules/openapi-generator/src/main/resources/Java/libraries/microprofile/enumClass.mustache
Outdated
Show resolved
Hide resolved
| {{#allowableValues}} | ||
| {{#enumVars}}{{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}} | ||
| {{#enumVars}}{{name}}({{^isNumeric}}{{dataType}}.valueOf({{/isNumeric}}{{{value}}}{{^isNumeric}}){{/isNumeric}}){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}} |
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.
Why is isFreeFormObject not used here, like in the other changed files?
Same question applies to modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/enumClass.mustache and modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/enumClass.mustache.
And the same also applies to using isUri.
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.
Hi @martin-mfg thx for the review. I've fixed the missing parts.
|
|
||
| public enum OrderStatusEnum { | ||
|
|
||
| PENDING(Object.valueOf("PENDING")), PROCESSING(Object.valueOf("PROCESSING")); |
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.
Object.valueOf doesn't exist. There are several other occurrences in other files as well. Please fix.
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.
After regenerating the samples the problem is solved.
…croprofile/enumClass.mustache Co-authored-by: martin-mfg <[email protected]>
|
please review the CI failures when you've time, e.g. https://github.com/OpenAPITools/openapi-generator/actions/runs/15417950869/job/43385774859?pr=21055 |
|
Hi I recently had the same issue and I found this PR that should solve it. |
PR checklist
Commit all changed files.
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*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)Technical Comittee
@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)
Description
The template file
src/main/resources/Java/modelInnerEnum.mustachewas using thevalueOf()method to create instances for enum fields. This does not work for every Object, becausevalueOf()is not implemented in every possible Object.BigDecimalfor example does not provide thevalueOf(BigDecimal)method. This behaviour results in invalid code through generation.To fix this, I decided to only use the
valueOfmethod, for non numeric types. It seems the decision to use thevalueOfmethod was, to fix a bug for Boolean values (see: PR-19815 ). So this fix should be non breaking.This PR closes #20188