Skip to content

[core] Restore sibling example for allOf with a single $ref (#23335) - #24081

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/issue-23335-allof-single-ref-sibling-example
Jun 23, 2026
Merged

[core] Restore sibling example for allOf with a single $ref (#23335)#24081
wing328 merged 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/issue-23335-allof-single-ref-sibling-example

Conversation

@seonwooj0810

@seonwooj0810 seonwooj0810 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #23335

Problem

When a model property is declared as allOf with a single $ref and has a sibling example, the generated @Schema annotation emits the literal string example = "null" instead of the declared example. This worked correctly in 6.x.

Example spec:

status:
  allOf:
    - $ref: '#/components/schemas/StatusEnum'
  example: ACTIVE
  description: Current status of the item.

Generated (kotlin-spring), before:

@Schema(example = "null", description = "Current status of the item.")
@get:JsonProperty("status") val status: StatusEnum? = null

Root cause

In DefaultCodegen.fromProperty(...), when a property is allOf with a single sub-schema, the working schema p is reassigned to the inner ($ref) schema and the outer schema is kept as original. property.example is then computed via toExampleValue(p) against the inner schema, which has no example, so toExampleValue returns the literal "null".

The later "restore original schema" block re-applies the outer schema's nullable, description, min/max, title, etc., but it never restores the example. (The default value is unaffected because it is recomputed after that block against original.)

Fix

Restore the example from the original (outer) schema in the same restore block, mirroring the existing handling of the other sibling attributes:

if (original.getExample() != null) {
    property.example = toExampleValue(original);
}

The change is in DefaultCodegen, so all generators that rely on property.example (java, kotlin, spring, …) benefit.

Tests

  • Added DefaultCodegenTest#testAllOfSingleRefSiblingExample, reusing 3_0/property-title.yaml (extended with sibling example values). It asserts the allOf: [ $ref ] property keeps Ref-Property-Example. Verified it fails without the fix (expected: <Ref-Property-Example> but was: <null>) and passes with it.
  • DefaultCodegenTest (160), JavaClientCodegenTest (238) and KotlinSpringServerCodegenTest (229) all pass.
  • No committed samples change: the only sample-input specs matching the allOf:[single $ref] + sibling example pattern are unit-test resources (property-title.yaml, allof_primitive.yaml), neither of which drives a bin/configs sample.

Verification done: reproduced the example = "null" symptom on master, confirmed root cause in DefaultCodegen.fromProperty restore block, added a failing-then-passing regression test, ran the affected codegen test classes, and checked there is no in-flight PR for this issue.


Summary by cubic

Fixes a regression where allOf: [ $ref ] properties ignored their sibling example, generating example = "null". Restores the declared example in generated schemas across Java/Kotlin/Spring (Fixes #23335).

  • Bug Fixes
    • Reapply the outer schema’s example in DefaultCodegen#fromProperty when handling allOf: [ $ref ].
    • Added regression test testAllOfSingleRefSiblingExample and extended 3_0/property-title.yaml with examples.

Written for commit 31b695f. Summary will update on new commits.

Review in cubic

…ools#23335)

When a property is declared as `allOf: [ $ref ]` with a sibling `example`,
fromProperty() reassigns the working schema to the inner $ref schema before
computing the example, so toExampleValue() runs against a schema that has no
example and returns the literal string "null". The subsequent
"restore original schema" block re-applies the outer schema's nullable,
description, min/max, title, etc. but not the example.

Restore the example from the original (outer) schema in that block, mirroring
the existing handling of the other sibling attributes. Regression from 6.x.

Fixes OpenAPITools#23335

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

@wing328

wing328 commented Jun 23, 2026

Copy link
Copy Markdown
Member

thanks for the fix

lgtm

@wing328
wing328 merged commit a179190 into OpenAPITools:master Jun 23, 2026
15 checks passed
@wing328 wing328 added this to the 7.24.0 milestone Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [kotlin-spring] allOf with single $ref loses sibling example in fromProperty

2 participants