-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
base: master
Are you sure you want to change the base?
[JAVA][BUG] Do not use valueOf for numeric types for generating inner enums #20293
Conversation
…do not use valueOf factory method for BigDecimals.
@timon-sbr thanks for the PR. Can you please add a test case or 2 in |
…ts-models-for-testing-okhttp-gson.yaml
@wing328 thanks for the review. I've added some test data to |
i did a test with https://raw.githubusercontent.com/OpenAPITools/openapi-generator/a8d3e7da44e268d32818e6d02d0a111d58f7bbea/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml using the latest master CLI JAR but the output compiles without issue is my understanding correct that the test spec (with the newly added test cases you just added) should generate output with compilation errors as described in the issue? |
Hi @wing328 the Test Spec I've added tests the bugfix, so the output should generate a valid result, which is the fix of the issue. |
In the issue, you mentioned
but I couldn't repeat the compilation errors using the test spec you updated in this PR: https://raw.githubusercontent.com/OpenAPITools/openapi-generator/a8d3e7da44e268d32818e6d02d0a111d58f7bbea/modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml in other words, how did you produce the compilation errors? |
Hi @wing328 sorry for the late response, I was in vacation. One important note: You also have to use resteasy as library to create the error (bin/configs/java-okhttp-gson.yaml): generatorName: java
outputDir: samples/client/petstore/java/okhttp-gson
library: okhttp-gson
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
nameMappings:
_type: underscoreType
type_: typeWithUnderscore
parameterNameMappings:
_type: underscoreType
type_: typeWithUnderscore
additionalProperties:
artifactId: petstore-okhttp-gson
hideGenerationTimestamp: true
useOneOfDiscriminatorLookup: true
disallowAdditionalPropertiesIfNotPresent: false
useReflectionEqualsHashCode:: true
library: resteasy #This line is important to reproduce the error
enumNameMappings:
s: LOWER_CASE_S
S: UPPER_CASE_S
operationIdNameMappings:
getArrayOfEnums: getFakeArrayofenums
fakeHealthGet: getFakeHealth |
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 @timon-sbr, thanks for the PR!
After reviewing your changes I extended them a bit. You can find the extended version, consisting of your commits and my commits here: martin-mfg#63
I assume that you want to see a successfully completed PR to OpenAPI Generator on your Github profile. Therefore I didn't open a competing PR of our combined changes to OpenAPI Generator. Instead, you can include my changes into your branch by merging this. I will then approve your PR here and it can get merged and you get the credit. :)
What did I change on top of your changes?
- applied your fix to more Java libraries
- fixed a problem in your yaml changes ("double" is not a valid type, but "number" is)
- copied your yaml changes to an additional test input file, thereby fulfilling @wing328's request discussed in the comments above
- removed one of the yaml changes in each of the two changed yaml files, because they triggered bugs in some sample configurations. Those bugs are not related to the problem fixed in this PR.
- merged master branch to resolve a merge conflict
extend PR 20293
Hi @martin-mfg thank you very much for the explanation and extending this bugfix to other libraries. I've merged your changes right now :) |
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.0
minor 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.mustache
was using thevalueOf()
method to create instances for enum fields. This does not work for every Object, becausevalueOf()
is not implemented in every possible Object.BigDecimal
for example does not provide thevalueOf(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 thevalueOf
method was, to fix a bug for Boolean values (see: PR-19815 ). So this fix should be non breaking.This PR closes #20188