mirror of
https://github.com/cave-story-randomizer/cave-story-randomizer
synced 2025-01-21 19:06:52 +00:00
26 lines
702 B
Python
26 lines
702 B
Python
from jsonschema import Draft7Validator, validators
|
|
|
|
|
|
def extend_with_default(validator_class):
|
|
validate_properties = validator_class.VALIDATORS["properties"]
|
|
|
|
def set_defaults(validator, properties, instance, schema):
|
|
for property, subschema in properties.items():
|
|
if "default" in subschema:
|
|
instance.setdefault(property, subschema["default"])
|
|
|
|
yield from validate_properties(
|
|
validator,
|
|
properties,
|
|
instance,
|
|
schema,
|
|
)
|
|
|
|
return validators.extend(
|
|
validator_class,
|
|
{"properties": set_defaults},
|
|
)
|
|
|
|
|
|
DefaultValidatingDraft7Validator = extend_with_default(Draft7Validator)
|