common.validation
validate_dict
def validate_dict(spec: Type[_TypedDict],
doc: StrAny,
path: str,
filter_f: TFilterFunc = None,
validator_f: TCustomValidator = None) -> None
Validate the doc
dictionary based on the given typed dictionary specification spec
.
Arguments:
spec
Type[_TypedDict] - The typed dictionary thatdoc
should conform to.doc
StrAny - The dictionary to validate.path
str - The string representing the location of the dictionary in a hierarchical data structure.filter_f
TFilterFunc, optional - A function to filter keys indoc
. It should returnTrue
for keys to be kept. Defaults to a function that keeps all keys.validator_f
TCustomValidator, optional - A function to perform additional validation for types not covered by this function. It should returnTrue
if the validation passes or raise DictValidationException on validation error. For types it cannot validate, it should return False to allow chaining. Defaults to a function that rejects all such types.
Raises:
DictValidationException
- If there are missing required fields, unexpected fields, type mismatches or unvalidated types indoc
compared tospec
.
Returns:
None