@@ -1420,17 +1420,24 @@ public static Schema unaliasSchema(OpenAPI openAPI,
14201420 }
14211421 } else if (isObjectSchema (ref )) {
14221422 boolean hasProps = ref .getProperties () != null && !ref .getProperties ().isEmpty ();
1423- if (hasProps ) {
1423+ if (!hasProps && (ref .getDefault () != null || ref .getExample () != null )) {
1424+ // Free‐form object WITH default/example → keep the $ref but copy defaults up
1425+
1426+ // clone the wrapper ($ref-only)…
1427+ Schema <?> wrapperCopy = (Schema <?>) deepCopy (schema );
1428+ // …then merge all the siblings from the component onto it
1429+ return mergeSiblingFields (ref , wrapperCopy );
1430+ } else if (hasProps ) {
14241431 // TODO we may need to check `hasSelfReference(openAPI, ref)` as a special/edge case:
14251432 // TODO we may also need to revise below to return `ref` instead of schema
14261433 // which is the last reference to the actual model/object
14271434 // hier this is real object model ← leave wrapped
14281435 return schema ;
14291436 } else {
1430- // ↳ free- form object (type: object) : same as map-fallback
1431- Schema copyObj = deepCopy (ref ); // deep-copy free-form object
1432- copyObj .set$ref (null ); // clear lingering $ref so we don’t recurse
1433- Schema unwrapped = unaliasSchema (openAPI , copyObj , schemaMappings );
1437+ // Free‐ form object WITHOUT default/example → unwrap into inline free-form
1438+ Schema <?> copyObj = deepCopy (ref );
1439+ copyObj .set$ref (null );
1440+ Schema <?> unwrapped = unaliasSchema (openAPI , copyObj , schemaMappings );
14341441 return mergeSiblingFields (schema , unwrapped );
14351442 }
14361443 }
@@ -1465,6 +1472,8 @@ private static Schema mergeSiblingFields(Schema original, Schema actual) {
14651472 if (original .getDescription () != null ) actual .setDescription (original .getDescription ());
14661473 if (original .getExample () != null ) actual .setExample (original .getExample ());
14671474 if (original .getDefault () != null ) actual .setDefault (original .getDefault ());
1475+ if (original .getType () != null ) actual .setType (original .getType ());
1476+ if (original .getFormat () != null ) actual .setFormat (original .getFormat ());
14681477
14691478 // --- read/write flags & deprecation
14701479 if (original .getReadOnly () != null ) actual .setReadOnly (original .getReadOnly ());
@@ -1584,7 +1593,7 @@ private static <T extends Schema> T deepCopy(T schema) {
15841593 // restore the original on the source
15851594 schema .setAdditionalProperties (addl );
15861595
1587- // 5) put it back on the clone, deep-copying if it's itself a Schema
1596+ // put it back on the clone, deep-copying if it's itself a Schema
15881597 if (addl instanceof Schema ) {
15891598 copy .setAdditionalProperties (deepCopy ((Schema ) addl ));
15901599 } else if (addl != null ) {
0 commit comments