19 lines
530 B
Python
19 lines
530 B
Python
from django.core.exceptions import ValidationError
|
|
|
|
from jsonschema import Draft4Validator
|
|
|
|
|
|
def schema_validator(schema):
|
|
def validate(value):
|
|
errors = []
|
|
validator = Draft4Validator(schema)
|
|
for error in sorted(validator.iter_errors(value), key=str):
|
|
errors.append(ValidationError(error.message))
|
|
if errors:
|
|
raise ValidationError(errors)
|
|
return validate
|
|
|
|
|
|
validate_schema = schema_validator(Draft4Validator.META_SCHEMA)
|
|
validate_schema.__name__ = 'validate_schema'
|