Validation Model module (ska_oso_services.validation.model)
- class ska_oso_services.validation.model.ValidationContext(*args: Any, **kwargs: Any)[source]
This models the input to all
Validator()functions and should provide all information that the Validator requires.
- class ska_oso_services.validation.model.ValidationIssue(*args: Any, **kwargs: Any)[source]
A single validation message that can be tied to a particular field in the object being validated. The field should be the JSONPath corresponding to the particular section of the object that is invalid.
- ska_oso_services.validation.model.Validator
The general Validator function type. It should take the entity to validate wrapped in a ValidationContext and return a list of ValidationIssues.
alias of
Callable[[ValidationContext[T]],list[ValidationIssue]]
- ska_oso_services.validation.model.check_relevant_context_contains(keys: list[str], validation_context: ValidationContext) None[source]
Performs a check that the keys are present in the relevant_context
- Raises:
ValueError – if any of the keys are not present
- ska_oso_services.validation.model.validate(entity_context: ValidationContext[T], validators: list[Callable[[ValidationContext[T]], list[ValidationIssue]]]) list[ValidationIssue][source]
Applies a set of validators to an entity and collects any resulting ValidationIssues into a single list.
- ska_oso_services.validation.model.validator(validator_func: Callable[[ValidationContext[T]], list[ValidationIssue]]) Callable[[ValidationContext[T]], list[ValidationIssue]][source]
A decorator to mark a
Validator()This decorator will combine the source_jsonpath from the input ValidationContext with any of the Validator output ValidationIssue fields. To handle nested Validator calls, the decorator will set the source_jsonpath back to the root before passing the ValidationContext to the decorated Validator. Ultimately this means that the callers of the Validators only need to worry about setting the source_jsonpath at the point the Validator is called, and the appending of nested results is handled by this decorator
- Raises:
ValueError – It will also perform a type check on the Validator signature, raising an error if the decorated function does not have the correct parameters or type hints.