@@ -1565,17 +1565,18 @@ public static String getParentName(Schema composedSchema, Map<String, Schema> al
15651565 List <String > refedWithoutDiscriminator = new ArrayList <>();
15661566
15671567 if (interfaces != null && !interfaces .isEmpty ()) {
1568+ List <String > parentNameCandidates = new ArrayList <>(interfaces .size ());
15681569 for (Schema schema : interfaces ) {
15691570 // get the actual schema
15701571 if (StringUtils .isNotEmpty (schema .get$ref ())) {
15711572 String parentName = getSimpleRef (schema .get$ref ());
15721573 Schema s = allSchemas .get (parentName );
15731574 if (s == null ) {
15741575 LOGGER .error ("Failed to obtain schema from {}" , parentName );
1575- return "UNKNOWN_PARENT_NAME" ;
1576+ parentNameCandidates . add ( "UNKNOWN_PARENT_NAME" ) ;
15761577 } else if (hasOrInheritsDiscriminator (s , allSchemas , new ArrayList <Schema >())) {
15771578 // discriminator.propertyName is used or x-parent is used
1578- return parentName ;
1579+ parentNameCandidates . add ( parentName ) ;
15791580 } else {
15801581 // not a parent since discriminator.propertyName or x-parent is not set
15811582 hasAmbiguousParents = true ;
@@ -1592,6 +1593,12 @@ public static String getParentName(Schema composedSchema, Map<String, Schema> al
15921593 }
15931594 }
15941595 }
1596+ if (parentNameCandidates .size () > 1 ) {
1597+ // unclear which one should be the parent
1598+ return null ;
1599+ } else if (parentNameCandidates .size () == 1 ) {
1600+ return parentNameCandidates .get (0 );
1601+ }
15951602 if (refedWithoutDiscriminator .size () == 1 && nullSchemaChildrenCount == 1 ) {
15961603 // One schema is a $ref and the other is the 'null' type, so the parent is obvious.
15971604 // In this particular case there is no need to specify a discriminator.
0 commit comments