fix(java): render enum default on allOf + $ref composed property (#24384)
Fixes #24384
Root cause
A property that references an enum via allOf + $ref with a sibling default (the standard OAS 3.0 idiom for attaching a default to a $ref) is parsed as a composed schema. AbstractJavaCodegen.toDefaultValue()'s composed-schema branch — added in #23971 to render object defaults — resolves the composition's effective properties via getComposedSchemaProperties() and, when that set is empty, returned null. For a composition wrapping an enum (or any non-object) there are no object properties, so the default was dropped. This is a regression between 7.23.0 and 7.24.0: previously this branch fell through to super.toDefaultValue(...).
Runtime impact: deserializing a payload without the property now yields null from the getter instead of the declared enum default.
Change
In the composed branch, when no object properties can be resolved, defer to super.toDefaultValue(schema) (the pre-#23971 behavior) so the raw default is emitted for later enum var-name conversion. Object compositions are unaffected and still go through toObjectDefaultValue(...), so the #23795 fix is preserved.
For the reporter's spec the spring/java generators again emit private CurrencyCode currency = CurrencyCode.EUR; instead of private @Nullable CurrencyCode currency;.
Test
Added AbstractJavaCodegenTest#toDefaultValueForComposedEnumWithDefaultTest, a sibling to the existing toDefaultValueForComposedObjectWithDefaultTest. It builds an allOf → enum $ref composed schema with a sibling default and asserts the rendered default is preserved. The test fails on current master (expected [EUR] but found [null]) and passes with this change.
Verification done: ./mvnw -pl modules/openapi-generator -am test -Dtest=AbstractJavaCodegenTest#... — both the new enum test and the existing object test pass (2 run, 0 failures); confirmed the new test fails without the source change. No templates/samples touched, so no sample regeneration is required.
Summary by cubic
Fixes a regression in Java generators where enum defaults on allOf + $ref properties were dropped. Restores proper field initialization so missing values use the declared enum default instead of null.
- Bug Fixes
- In
AbstractJavaCodegen.toDefaultValue, when a composed schema has no object properties, fall back tosuper.toDefaultValue(...)to preserve non-object defaults (enums/scalars). - Keeps object default rendering intact; only affects non-object compositions.
- Adds a unit test for
allOf+$refenum with a siblingdefaultto prevent regressions.
- In