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

[JAVA][BUG] Do not use valueOf for numeric types for generating inner enums #20293

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

timon-sbr
Copy link

@timon-sbr timon-sbr commented Dec 11, 2024

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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.mustache was using the valueOf() method to create instances for enum fields. This does not work for every Object, because valueOf() is not implemented in every possible Object. BigDecimal for example does not provide the valueOf(BigDecimal) method. This behaviour results in invalid code through generation.
To fix this, I decided to only use the valueOf method, for non numeric types. It seems the decision to use the valueOf method was, to fix a bug for Boolean values (see: PR-19815 ). So this fix should be non breaking.

This PR closes issue-2694445144

…do not use valueOf factory method for BigDecimals.
@timon-sbr timon-sbr changed the title bugfix-20188: [JAVA][BUG] Do not use valueOf for numeric types for generating inner enums [JAVA][BUG] Do not use valueOf for numeric types for generating inner enums Dec 12, 2024
@wing328 wing328 added this to the 7.11.0 milestone Dec 14, 2024
@wing328
Copy link
Member

wing328 commented Dec 15, 2024

@timon-sbr thanks for the PR.

Can you please add a test case or 2 in modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml and then regenerate the samples?

@timon-sbr
Copy link
Author

@wing328 thanks for the review. I've added some test data to modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml and regenerated the samples. Can you please check, if this is enough? I'm not sure, if I've also have to add java code to test the behaviour.

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.

[BUG][JAVA] Inner Enum generation with BigDecimal values results in compilation error
2 participants