eyconf.validation¶
Validating configuration data against schemas.
Functions
|
Recursively modifies a JSON schema to allow null values for all fields. |
|
Validate the provided data against the schema and return the dataclass instance. |
|
Validate the provided data against the given schema. |
Exceptions
|
Exception raised for configuration validation errors. |
|
Exception raised for multiple configuration validation errors. |
Module Functions
- eyconf.validation.allow_none_in_schema(schema: dict | list) dict¶
Recursively modifies a JSON schema to allow null values for all fields.
This is needed to parse Optional fields that hold dataclasses. May need a revisit later.
- eyconf.validation.validate(data: D | dict, schema: type[D]) D¶
Validate the provided data against the schema and return the dataclass instance.
This function first converts the schema dataclass to a JSON schema using to_json_schema, then validates the provided data against this schema using validate_json. If validation is successful, it returns an instance of the schema dataclass populated with the validated data.
For more controls over validation, consider using to_json_schema and validate_json.
- Parameters:
dict) (data (D |) – The data to be validated, either as a dictionary or an instance of the schema dataclass.
(type[D]) (schema) – The dataclass type representing the schema to validate against.
- Returns:
An instance of the schema dataclass populated with the validated data.
- Return type:
D
- Raises:
ConfigurationError – If the data does not comply with the schema,: this error is raised with details of the violations.
- eyconf.validation.validate_json(data: DataclassInstance | dict, schema: dict) None¶
Validate the provided data against the given schema.
This function uses the Draft202012Validator to check if the data conforms to the specified schema. If there are any validation errors, it raises a ConfigurationError containing the details of the errors.
- Parameters:
(dict) (schema) – The data to be validated.
(dict) – The JSON schema to validate against.
- Raises:
ConfigurationError – If the data does not comply with the schema,: this error is raised with details of the violations.
Module Exceptions
- exception eyconf.validation.ConfigurationError(message='Configuration error', section=None)¶
Exception raised for configuration validation errors.
- exception eyconf.validation.MultiConfigurationError(errors: list[ConfigurationError])¶
Exception raised for multiple configuration validation errors.