fix: set isOverridden from the model's own properties rather than only when unset

VI
2mo ago
+447-2

Fixes #24778.

A property inherited through allOf only produced an overriding fluent setter when the parent schema happened to be declared before the child. Moving MyPets above Pet in the reporter's spec drops Cat's setter entirely — the generated class still extends Pet, but the @Override public Cat petType(...) method is gone.

Cause

addVars marked a parent property as overridden only when the flag was still unset:

if (cm != null && cm.allVars == vars && cp.isOverridden == null) {
    cp.isOverridden = true;
}

fromProperty caches CodegenProperty instances in schemaCodegenPropertyCache, 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 to false, the == null guard 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 allVars is overridden when the model did not declare it itself:

if (cm != null && cm.allVars == vars) {
    cp.isOverridden = !varsMap.containsKey(key);
}

varsMap is already built from cm.vars a few lines above for exactly this purpose, so this reuses the information rather than depending on the mutable state of a shared instance.

Test

testOverrideSetterWhenChildIsDeclaredBeforeParent generates from allOf_composition_discriminator_child_first.yaml, which is the reporter's spec with MyPets moved above Pet, and asserts Cat gets the overriding setter. It fails on master and passes with this change.

The existing testForJavaApacheHttpClientOverrideSetter covers the opposite order and still passes, including its assertion that Pet declares petType without @Override — so the parent side is unaffected.

Verification

Full modules/openapi-generator suite: 4952 tests, 0 failures. The single error is KotlinTestUtilsTest.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 allOf properties losing their overriding fluent setter when the child schema is declared before the parent (#24778). The old logic only marked a property as overridden when isOverridden was still null, but fromProperty caches shared CodegenProperty instances, so whichever model was processed first left the flag false. The flag is now derived from whether the model declared the property itself via the existing varsMap.

Adds a regression test using a child-first spec that asserts Cat generates the overriding petType setter. Committed Java samples were regenerated to restore the missing overriding fluent setters; all sample diffs are additions, so only the restored setters change.