@@ -620,7 +620,7 @@ def make_avsc_object(json_data: JsonDataType, names: Optional[Names] = None) ->
620620 raise SchemaParseException (fail_msg )
621621
622622
623- def is_subtype (existing : PropType , new : PropType ) -> bool :
623+ def is_subtype (types : Dict [ str , Any ], existing : PropType , new : PropType ) -> bool :
624624 """Check if a new type specification is compatible with an existing type spec."""
625625 if existing == new :
626626 return True
@@ -632,46 +632,35 @@ def is_subtype(existing: PropType, new: PropType) -> bool:
632632 if isinstance (new , list ) and "null" in new :
633633 return False
634634 return True
635- if (
636- isinstance (existing , dict )
637- and "type" in existing
638- and existing ["type" ] == "array"
639- and isinstance (new , dict )
640- and "type" in new
641- and new ["type" ] == "array"
642- ):
643- return is_subtype (existing ["items" ], new ["items" ])
644- if (
645- isinstance (existing , dict )
646- and "type" in existing
647- and existing ["type" ] == "enum"
648- and isinstance (new , dict )
649- and "type" in new
650- and new ["type" ] == "enum"
651- ):
652- return is_subtype (existing ["symbols" ], new ["symbols" ])
653- if (
654- isinstance (existing , dict )
655- and "type" in existing
656- and existing ["type" ] == "record"
657- and isinstance (new , dict )
658- and "type" in new
659- and new ["type" ] == "record"
660- ):
661- for new_field in cast (List [Dict [str , Any ]], new ["fields" ]):
662- new_field_missing = True
663- for existing_field in cast (List [Dict [str , Any ]], existing ["fields" ]):
664- if new_field ["name" ] == existing_field ["name" ]:
665- if not is_subtype (existing_field ["type" ], new_field ["type" ]):
666- return False
667- new_field_missing = False
668- if new_field_missing :
669- return False
670- return True
635+ if isinstance (existing , str ) and existing in types :
636+ return is_subtype (types , types [existing ], new )
637+ if isinstance (new , str ) and new in types :
638+ return is_subtype (types , existing , types [new ])
639+ if isinstance (existing , dict ) and isinstance (new , dict ):
640+ if "extends" in new and new ["extends" ] == existing .get ("name" ):
641+ return True
642+ if existing .get ("type" ) == "array" and new .get ("type" ) == "array" :
643+ return is_subtype (types , existing ["items" ], new ["items" ])
644+ if existing .get ("type" ) == "enum" and new .get ("type" ) == "enum" :
645+ return is_subtype (types , existing ["symbols" ], new ["symbols" ])
646+ if existing .get ("type" ) == "record" and new .get ("type" ) == "record" :
647+ for new_field in cast (List [Dict [str , Any ]], new ["fields" ]):
648+ new_field_missing = True
649+ for existing_field in cast (List [Dict [str , Any ]], existing ["fields" ]):
650+ if new_field ["name" ] == existing_field ["name" ]:
651+ if not is_subtype (types , existing_field ["type" ], new_field ["type" ]):
652+ return False
653+ new_field_missing = False
654+ if new_field_missing :
655+ return False
656+ return True
671657 if isinstance (existing , list ) and isinstance (new , list ):
672658 missing = False
673- for _type in new :
674- if _type not in existing and (not is_subtype (existing , cast (PropType , _type ))):
659+ for _type_new in new :
660+ if _type_new not in existing and not any (
661+ is_subtype (types , cast (PropType , _type_existing ), cast (PropType , _type_new ))
662+ for _type_existing in existing
663+ ):
675664 missing = True
676665 return not missing
677666 return False
0 commit comments