Repository navigation
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 25 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
|
On the review comments about missing imports: they are valid, and the gap predates this PR. On 159d54e adds the instantiation type to the model imports when it has an import mapping, either a default one or one passed with
|
Since OpenAPITools#25001 the add/put item helpers of the Java pojo templates create a hard-coded ArrayList, LinkedHashSet or HashMap when the field is null, ignoring the configured instantiationTypes. AbstractJavaCodegen now exposes the instantiation type of each container property as x-container-instantiation-type, and the templates use it.
…mapping The field initializer and the item helpers reference the configured instantiation type, but only the default ArrayList, LinkedHashSet and HashMap were imported. Generators without a java.util wildcard import, such as the native client, did not compile with custom instantiationTypes.
fb259c6 to
9f48061
Compare
|
Closing, since #25649 fixed #25642 on master with the same approach (helpers and the instantiation type import). Thanks @AndreyVMarkelov for the review. |
fix #25642
Since #25001 the
add<Name>Itemandput<Name>Itemhelpers in the Javapojo.mustachetemplates create a hard-codedArrayList,LinkedHashSetorHashMapwhen the field is null. The field initializer still usesinstantiationTypes, so the two disagree. With a type mapping such asmap=SequencedMapthe model does not compile, and with onlymap=LinkedHashMapthe helper silently switches to aHashMap.{{{defaultValue}}}cannot go back into the helpers, because since #25001 it can be a filled container built from the schemadefault. Instead,AbstractJavaCodegen.postProcessModelPropertynow setsx-container-instantiation-typeon each container property frominstantiationTypes(array,setormap), and the 21 Java templates touched by #25001 use it in the helpers. With the default instantiation types the generated code is unchanged.The configured instantiation type is also added to the model imports when it has an import mapping (a default one or one from
--import-mappings). Before this, onlyArrayList,LinkedHashSetandHashMapwere imported, so the field initializer already failed to compile with custominstantiationTypesin generators withoutimport java.util.*;, such as thenativeclient.Tests:
SpringCodegenTest.testItemHelpersUseInstantiationTypes_issue25642andJavaClientCodegenTest.testItemHelpersUseInstantiationTypes_issue25642: withmap=LinkedHashMap,array=LinkedListandset=TreeSet, the helpers create those types, and the Java client model imports them. The Spring test fails without the fix (this.entries = new HashMap<>();).java+nativeclient generated with these instantiation types and import mappings, including a nullable array, compiles withmvn compile.SpringCodegenTest,JavaClientCodegenTest,AbstractJavaCodegenTest,JavaModelTestandJavaJAXRSSpecServerCodegenTestpass (1161 tests).instantiationTypes.PR checklist
Java technical committee: @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg @KannaKim @AndreyVMarkelov
Java Spring technical committee: @cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente
cc @jorgerod, who changed these helpers in #25001