Fix AbstractJavaCodegen ability to customize container types#13550
Open
dmivankov wants to merge 3 commits into
Open
Fix AbstractJavaCodegen ability to customize container types#13550dmivankov wants to merge 3 commits into
dmivankov wants to merge 3 commits into
Conversation
After OpenAPITools#5466 java codegen emits Set for array with uniqueItems=true which has its downsides - easy to lose track of element order (it can be important) - easy to lose ordering by switching between java Set flavors (HashSet vs LinkedHashSet) somewhere down the line - bigger divergence from original json types (either array or object) Luckily types can be customized/overriden by extending the generator: - extend JavaClientCodegen for example - in constructor do ```java super(); // import/interface type typeMapping().put("set", typeMapping().get("array")); // concrete type instantiationTypes().put("set", instantiationTypes().get("array")); ``` But sometimes it won't work because of missing ArrayList import, can be fixed by also doing ```java importMapping().put("LinkedHashSet", importMapping().get("ArrayList")); ``` Looks like a bug of assuming "set" fields are instantiated with LinkedHashSet, let's fix it by using type mappings.
Author
|
Member
|
thanks for the PR. can you please add some tests in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java to cover this change? |
Author
|
Added a test that was failing without this change |
Member
|
when you've time, can you please resolve the merge conflicts and PM me via Slack when it's done? https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g |
Author
|
Mechanically resolved the conflict but didn't try to retest locally, will need to remember more context first :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix for #13549
After #5466 java codegen emits Set for array with uniqueItems=true which has its downsides
Luckily types can be customized/overriden by extending the generator:
But sometimes it won't work because of missing ArrayList import, can be fixed by also doing
Looks like a bug of assuming "set" fields are instantiated with LinkedHashSet,
let's fix it by using type mappings.
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.1.0) (minor release - breaking changes with fallbacks),7.0.x(breaking changes without fallbacks)