DefaultingValidator#
- class lsst.ts.salobj.DefaultingValidator(schema, StandardValidatorClass=<class 'jsonschema.validators.Draft7Validator'>)#
Bases:
objectA wrapper for jsonschema validators that applies default values.
- Parameters:
schema (
dict) – Schema against which to validate.ValidatorClass (
jsonschema.protocols.Validator, optional) – jsonschema validator class, e.g.jsonschema.Draft7Validator.
Notes
Default values are handled at most 2 levels deep in an object hierarchy. For deeper hierarchies, set the default at a higher level. For example:
type: object properties: number1: type: number default: 1 subdict1: type: object properties: number2: type: number default: 2 subdict2: type: object properties: number3: type: number # default is ignored this deep; set it at a higher level default: number3: 3
This class is not a
jsonschema.IValidatorbut it contains two validators:defaults_validator: a validator that sets default values in the data being validated
final_validator: a standard validator that does not alter the data being validated.
- Parameters:
StandardValidatorClass (
Type[Draft7Validator], default:<class 'jsonschema.validators.Draft7Validator'>)
Methods Summary
validate(data_dict)Validate data.
Methods Documentation
- validate(data_dict)#
Validate data.
Set missing values based on defaults in the schema, then check the final result against the schema (in case any defaults are not valid).
- Parameters:
data_dict (
dictorNone) – Data to validate. If None then an empty dict is used.- Returns:
result – Validated data. A copy of data_dict with missing values that have defaults set to those defaults.
- Return type:
- Raises:
jsonschema.exceptions.ValidationError – If the data does not match the schema.