@@ -318,8 +318,10 @@ def _validate_compatible(weak_schema, strong_schema):
318318 if weak_schema ['type' ] == 'array' :
319319 _validate_compatible (weak_schema ['items' ], strong_schema ['items' ])
320320 elif weak_schema ['type' ] == 'object' :
321+ # If the weak schema allows for arbitrary keys (is a map),
322+ # the strong schema must also allow for arbitrary keys.
321323 if weak_schema .get ('additionalProperties' ):
322- if not strong_schema .get ('additionalProperties' ):
324+ if not strong_schema .get ('additionalProperties' , True ):
323325 raise ValueError ('Incompatible types: map vs object' )
324326 _validate_compatible (
325327 weak_schema ['additionalProperties' ],
@@ -328,12 +330,15 @@ def _validate_compatible(weak_schema, strong_schema):
328330 if required not in weak_schema ['properties' ]:
329331 raise ValueError (f"Missing or unknown property '{ required } '" )
330332 for name , spec in weak_schema .get ('properties' , {}).items ():
333+
331334 if name in strong_schema ['properties' ]:
332335 try :
333336 _validate_compatible (spec , strong_schema ['properties' ][name ])
334337 except Exception as exn :
335338 raise ValueError (f"Incompatible schema for '{ name } '" ) from exn
336- elif not strong_schema .get ('additionalProperties' ):
339+ elif not strong_schema .get ('additionalProperties' , True ):
340+ # The property is not explicitly in the strong schema, and the strong
341+ # schema does not allow for extra properties.
337342 raise ValueError (
338343 f"Prohibited property: '{ name } '; "
339344 "perhaps additionalProperties: False is missing?" )
0 commit comments