@@ -1573,17 +1573,18 @@ public static String getParentName(Schema composedSchema, Map<String, Schema> al
15731573 List <String > refedWithoutDiscriminator = new ArrayList <>();
15741574
15751575 if (interfaces != null && !interfaces .isEmpty ()) {
1576+ List <String > parentNameCandidates = new ArrayList <>(interfaces .size ());
15761577 for (Schema schema : interfaces ) {
15771578 // get the actual schema
15781579 if (StringUtils .isNotEmpty (schema .get$ref ())) {
15791580 String parentName = getSimpleRef (schema .get$ref ());
15801581 Schema s = allSchemas .get (parentName );
15811582 if (s == null ) {
15821583 LOGGER .error ("Failed to obtain schema from {}" , parentName );
1583- return "UNKNOWN_PARENT_NAME" ;
1584+ parentNameCandidates . add ( "UNKNOWN_PARENT_NAME" ) ;
15841585 } else if (hasOrInheritsDiscriminator (s , allSchemas , new ArrayList <Schema >())) {
15851586 // discriminator.propertyName is used or x-parent is used
1586- return parentName ;
1587+ parentNameCandidates . add ( parentName ) ;
15871588 } else {
15881589 // not a parent since discriminator.propertyName or x-parent is not set
15891590 hasAmbiguousParents = true ;
@@ -1600,6 +1601,12 @@ public static String getParentName(Schema composedSchema, Map<String, Schema> al
16001601 }
16011602 }
16021603 }
1604+ if (parentNameCandidates .size () > 1 ) {
1605+ // unclear which one should be the parent
1606+ return null ;
1607+ } else if (parentNameCandidates .size () == 1 ) {
1608+ return parentNameCandidates .get (0 );
1609+ }
16031610 if (refedWithoutDiscriminator .size () == 1 && nullSchemaChildrenCount == 1 ) {
16041611 // One schema is a $ref and the other is the 'null' type, so the parent is obvious.
16051612 // In this particular case there is no need to specify a discriminator.
0 commit comments