@@ -329,24 +329,7 @@ private List<Map<String, Object>> generateExamplesForSchema(String name, Schema
329329 }
330330
331331 if (hasOneOfOrAnyOf ) {
332- List <Map <String , Object >> oneOfAnyOfExamples = resolveAnyOfOneOfSchemaProperties (name , schema );
333-
334- if (!parentPropertyExamples .isEmpty ()) {
335- List <Map <String , Object >> mergedExamples = new ArrayList <>();
336- for (Map <String , Object > oneOfExample : oneOfAnyOfExamples ) {
337- for (Map <String , Object > parentExample : parentPropertyExamples ) {
338- Map <String , Object > merged = new HashMap <>(oneOfExample );
339-
340- for (Map .Entry <String , Object > entry : parentExample .entrySet ()) {
341- merged .putIfAbsent (entry .getKey (), entry .getValue ());
342- }
343- mergedExamples .add (merged );
344- }
345- }
346- examples = combineExampleLists (examples , mergedExamples );
347- } else {
348- examples = combineExampleLists (examples , oneOfAnyOfExamples );
349- }
332+ examples = handleAnyOrOneOf (name , schema , parentPropertyExamples , examples );
350333 }
351334
352335 if (CatsModelUtils .isArraySchema (schema )) {
@@ -369,6 +352,28 @@ private List<Map<String, Object>> generateExamplesForSchema(String name, Schema
369352 return examples ;
370353 }
371354
355+ private List <Map <String , Object >> handleAnyOrOneOf (String name , Schema schema , List <Map <String , Object >> parentPropertyExamples , List <Map <String , Object >> examples ) {
356+ List <Map <String , Object >> oneOfAnyOfExamples = resolveAnyOfOneOfSchemaProperties (name , schema );
357+
358+ if (!parentPropertyExamples .isEmpty ()) {
359+ List <Map <String , Object >> mergedExamples = new ArrayList <>();
360+ for (Map <String , Object > oneOfExample : oneOfAnyOfExamples ) {
361+ for (Map <String , Object > parentExample : parentPropertyExamples ) {
362+ Map <String , Object > merged = new HashMap <>(oneOfExample );
363+
364+ for (Map .Entry <String , Object > entry : parentExample .entrySet ()) {
365+ merged .putIfAbsent (entry .getKey (), entry .getValue ());
366+ }
367+ mergedExamples .add (merged );
368+ }
369+ }
370+ examples = combineExampleLists (examples , mergedExamples );
371+ } else {
372+ examples = combineExampleLists (examples , oneOfAnyOfExamples );
373+ }
374+ return examples ;
375+ }
376+
372377 private Map formatExampleAsMap (Object fromExample ) {
373378 if (!(fromExample instanceof Map )) {
374379 Map <String , Object > example = new HashMap <>();
@@ -662,18 +667,17 @@ private Object matchToEnumOrEmpty(String name, Schema innerSchema, String proper
662667 .stream ()
663668 .filter (discriminator -> discriminator .getPropertyName ().equalsIgnoreCase (propertyName ) && discriminator .getMapping () != null )
664669 .findFirst ()
665- .map (discriminator -> {
666- // Find the enum value that maps to this schema name
667- return discriminator .getMapping ().entrySet ().stream ()
668- .filter (entry -> {
669- String schemaRef = entry .getValue ();
670- String schemaName = CatsModelUtils .getSimpleRef (schemaRef );
671- return schemaName .equalsIgnoreCase (name );
672- })
673- .map (Map .Entry ::getKey )
674- .findFirst ()
675- .orElse ("" );
676- })
670+ .map (discriminator ->
671+ // Find the enum value that maps to this schema name
672+ discriminator .getMapping ().entrySet ().stream ()
673+ .filter (entry -> {
674+ String schemaRef = entry .getValue ();
675+ String schemaName = CatsModelUtils .getSimpleRef (schemaRef );
676+ return schemaName .equalsIgnoreCase (name );
677+ })
678+ .map (Map .Entry ::getKey )
679+ .findFirst ()
680+ .orElse ("" ))
677681 .orElse ("" );
678682
679683 if (!resultFromMapping .isEmpty ()) {
0 commit comments