1 from functools import reduce
2 from typing import Any, Callable, Dict
5 from .error_reporting import detailed_errors, ValidationError
6 from .extra_validations import EXTRA_VALIDATIONS
7 from .fastjsonschema_exceptions import JsonSchemaException, JsonSchemaValueException
8 from .fastjsonschema_validations import validate as _validate
15 "JsonSchemaException",
16 "JsonSchemaValueException",
20 FORMAT_FUNCTIONS: Dict[str, Callable[[str], bool]] = {
21 fn.__name__.replace("_", "-"): fn
22 for fn in formats.__dict__.values()
23 if callable(fn) and not fn.__name__.startswith("_")
27 def validate(data: Any) -> bool:
28 """Validate the given ``data`` object using JSON Schema
29 This function raises ``ValidationError`` if ``data`` is invalid.
31 with detailed_errors():
32 _validate(data, custom_formats=FORMAT_FUNCTIONS)
33 reduce(lambda acc, fn: fn(acc), EXTRA_VALIDATIONS, data)