fix: set isOverridden from the model's own properties rather than only when unset - #24823
fix: set isOverridden from the model's own properties rather than only when unset#24823vivekkumarq wants to merge 2 commits into
Conversation
…y when unset A property inherited through allOf only produced an overriding fluent setter when the parent schema happened to be declared before the child. Reordering the components so the child comes first dropped the setter entirely. addVars marked a parent property as overridden only when isOverridden was still null. fromProperty caches CodegenProperty instances in schemaCodegenPropertyCache, so by the time a child model reached the cached property, whichever model was processed first had already set the flag to false and the guard no longer applied. Which model got there first depends on the order the schemas appear in the document. Assign the flag from the condition it actually expresses: a property in allVars is overridden when the model did not declare it itself. Fixes OpenAPITools#24778
The ordering fix restores overriding fluent setters that the affected samples were missing, all additions.
|
Correcting something I got wrong in the description above: I wrote that no samples needed regenerating. That was an assumption I had not tested, and the The regenerated output is worth a look, because it makes the case better than my synthetic spec did: Every changed line is an addition — 62 overriding fluent setters that these samples were silently missing, for example in + @Override
+ public BarRef name(@jakarta.annotation.Nullable String name) {
+ this.setName(name);
+ return this;
+ }So this is not only reachable through a deliberately reordered document: Scope of the regeneration: Unchanged from before: full |
Fixes #24778.
A property inherited through
allOfonly produced an overriding fluent setter when the parent schema happened to be declared before the child. MovingMyPetsabovePetin the reporter's spec dropsCat's setter entirely — the generated class still extendsPet, but the@Override public Cat petType(...)method is gone.Cause
addVarsmarked a parent property as overridden only when the flag was still unset:fromPropertycachesCodegenPropertyinstances inschemaCodegenPropertyCache, so the instance a child model receives for an inherited property is frequently the same object another model already processed. Once any model has set the flag tofalse, the== nullguard no longer applies and the property is never marked as overridden. Which model reaches the cached instance first depends on the order the schemas appear in the document, which is what makes the symptom order-dependent.Change
Assign the flag from the condition it actually expresses — a property in
allVarsis overridden when the model did not declare it itself:varsMapis already built fromcm.varsa few lines above for exactly this purpose, so this reuses the information rather than depending on the mutable state of a shared instance.Test
testOverrideSetterWhenChildIsDeclaredBeforeParentgenerates fromallOf_composition_discriminator_child_first.yaml, which is the reporter's spec withMyPetsmoved abovePet, and assertsCatgets the overriding setter. It fails on master and passes with this change.The existing
testForJavaApacheHttpClientOverrideSettercovers the opposite order and still passes, including its assertion thatPetdeclarespetTypewithout@Override— so the parent side is unaffected.Verification
Full
modules/openapi-generatorsuite: 4952 tests, 0 failures. The single error isKotlinTestUtilsTest.testNormalCompile, which fails identically on unmodified master on my machine because my checkout path contains a space and the Kotlin compiler receives it percent-encoded (/C:/Users/VIVEK%20KUMAR/...). It is unrelated to this change.No samples needed regenerating: every committed sample keeps its current declaration order, so none of the generated output changes.
Summary by cubic
Fixes inherited
allOfproperties losing their overriding fluent setter when the child schema is declared before the parent (#24778). The old logic only marked a property as overridden whenisOverriddenwas still null, butfromPropertycaches sharedCodegenPropertyinstances, so whichever model was processed first left the flagfalse. The flag is now derived from whether the model declared the property itself via the existingvarsMap.Adds a regression test using a child-first spec that asserts
Catgenerates the overridingpetTypesetter. Committed Java samples were regenerated to restore the missing overriding fluent setters; all sample diffs are additions, so only the restored setters change.Written for commit ba72da8. Summary will update on new commits.