Merge pull request #1946 from hroff-1902/validator-cosmetics
minor: json validator cosmetics
This commit is contained in:
commit
38712f8120
@ -34,13 +34,17 @@ def set_loggers(log_level: int = 0) -> None:
|
|||||||
logging.getLogger('telegram').setLevel(logging.INFO)
|
logging.getLogger('telegram').setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def _extend_with_default(validator_class):
|
def _extend_validator(validator_class):
|
||||||
validate_properties = validator_class.VALIDATORS["properties"]
|
"""
|
||||||
|
Extended validator for the Freqtrade configuration JSON Schema.
|
||||||
|
Currently it only handles defaults for subschemas.
|
||||||
|
"""
|
||||||
|
validate_properties = validator_class.VALIDATORS['properties']
|
||||||
|
|
||||||
def set_defaults(validator, properties, instance, schema):
|
def set_defaults(validator, properties, instance, schema):
|
||||||
for prop, subschema in properties.items():
|
for prop, subschema in properties.items():
|
||||||
if "default" in subschema:
|
if 'default' in subschema:
|
||||||
instance.setdefault(prop, subschema["default"])
|
instance.setdefault(prop, subschema['default'])
|
||||||
|
|
||||||
for error in validate_properties(
|
for error in validate_properties(
|
||||||
validator, properties, instance, schema,
|
validator, properties, instance, schema,
|
||||||
@ -48,11 +52,11 @@ def _extend_with_default(validator_class):
|
|||||||
yield error
|
yield error
|
||||||
|
|
||||||
return validators.extend(
|
return validators.extend(
|
||||||
validator_class, {"properties": set_defaults},
|
validator_class, {'properties': set_defaults}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
ValidatorWithDefaults = _extend_with_default(Draft4Validator)
|
FreqtradeValidator = _extend_validator(Draft4Validator)
|
||||||
|
|
||||||
|
|
||||||
class Configuration(object):
|
class Configuration(object):
|
||||||
@ -339,7 +343,7 @@ class Configuration(object):
|
|||||||
:return: Returns the config if valid, otherwise throw an exception
|
:return: Returns the config if valid, otherwise throw an exception
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
ValidatorWithDefaults(constants.CONF_SCHEMA).validate(conf)
|
FreqtradeValidator(constants.CONF_SCHEMA).validate(conf)
|
||||||
return conf
|
return conf
|
||||||
except ValidationError as exception:
|
except ValidationError as exception:
|
||||||
logger.critical(
|
logger.critical(
|
||||||
|
Loading…
Reference in New Issue
Block a user