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. Defaults to a function that rejects all such types.filter_required
TFilterFunc, optional - A function to filter out required fields, useful for testing historic versions of dict that might now have certain fields yet.
Raises:
DictValidationException
- If there are missing required fields, unexpected fields, type mismatches or unvalidated types indoc
compared tospec
.
Returns:
None