[core] Restore sibling example for allOf with a single $ref (#23335) - #24081
Merged
wing328 merged 1 commit intoJun 23, 2026
Conversation
…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
Member
|
thanks for the fix lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #23335
Problem
When a model property is declared as
allOfwith a single$refand has a siblingexample, the generated@Schemaannotation emits the literal stringexample = "null"instead of the declared example. This worked correctly in 6.x.Example spec:
Generated (kotlin-spring), before:
Root cause
In
DefaultCodegen.fromProperty(...), when a property isallOfwith a single sub-schema, the working schemapis reassigned to the inner ($ref) schema and the outer schema is kept asoriginal.property.exampleis then computed viatoExampleValue(p)against the inner schema, which has no example, sotoExampleValuereturns 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 theexample. (Thedefaultvalue is unaffected because it is recomputed after that block againstoriginal.)Fix
Restore the example from the
original(outer) schema in the same restore block, mirroring the existing handling of the other sibling attributes:The change is in
DefaultCodegen, so all generators that rely onproperty.example(java, kotlin, spring, …) benefit.Tests
DefaultCodegenTest#testAllOfSingleRefSiblingExample, reusing3_0/property-title.yaml(extended with siblingexamplevalues). It asserts theallOf: [ $ref ]property keepsRef-Property-Example. Verified it fails without the fix (expected: <Ref-Property-Example> but was: <null>) and passes with it.DefaultCodegenTest(160),JavaClientCodegenTest(238) andKotlinSpringServerCodegenTest(229) all pass.allOf:[single $ref] + sibling examplepattern are unit-test resources (property-title.yaml,allof_primitive.yaml), neither of which drives abin/configssample.Verification done: reproduced the
example = "null"symptom on master, confirmed root cause inDefaultCodegen.fromPropertyrestore 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 siblingexample, generatingexample = "null". Restores the declared example in generated schemas across Java/Kotlin/Spring (Fixes #23335).exampleinDefaultCodegen#fromPropertywhen handlingallOf: [ $ref ].testAllOfSingleRefSiblingExampleand extended3_0/property-title.yamlwith examples.Written for commit 31b695f. Summary will update on new commits.