@@ -489,12 +489,12 @@ def validate_additional_properties(self, valid_response, response):
489489 except Exception :
490490 return False
491491
492- def validate_definition (self , definition_name : str , dict_to_test : Dict , definition : Dict = None ):
492+ def validate_definition (self , definition_name : str , expected_value : Dict , definition : Dict = None ):
493493 """Validate the given dict according to the given definition.
494494
495495 Args:
496496 definition_name: name of the the definition.
497- dict_to_test : dict to test.
497+ expected_value : dict or scalar value to test.
498498 definition: definition
499499
500500 Returns:
@@ -507,19 +507,23 @@ def validate_definition(self, definition_name: str, dict_to_test: Dict, definiti
507507
508508 # Check all required in dict_to_test
509509 spec_def = definition or self .specification ['definitions' ][definition_name ]
510- all_required_keys_present = all (req in dict_to_test .keys () for req in spec_def .get ('required' , {}))
511- if 'required' in spec_def and not all_required_keys_present :
512- return False
510+ if isinstance (expected_value , dict ):
511+ all_required_keys_present = all (req in expected_value .keys () for req in spec_def .get ('required' , {}))
512+ if 'required' in spec_def and not all_required_keys_present :
513+ return False
513514
514- # Check no extra arg & type
515- properties_dict = spec_def .get ('properties' , {})
516- for key , value in dict_to_test .items ():
517- if value is not None :
518- if key not in properties_dict : # Extra arg
519- return False
520- else : # Check type
521- if not self ._validate_type (properties_dict [key ], value ):
515+ # Check no extra arg & type
516+ properties_dict = spec_def .get ('properties' , {})
517+ for key , value in expected_value .items ():
518+ if value is not None :
519+ if key not in properties_dict : # Extra arg
522520 return False
521+ else : # Check type
522+ if not self ._validate_type (properties_dict [key ], value ):
523+ return False
524+ else :
525+ # Definition corresponds to scalar value (string for instance)
526+ return self .check_type (expected_value , spec_def ['type' ])
523527
524528 return True
525529
0 commit comments