Source code for ska_tmc_cdm.schemas.telmodel_validation

"""
This module contains high-level functions that invoke validation against
the SKA Telmodel schemas.
"""

from typing import Callable, Optional

from ..jsonschema.json_schema import JsonSchema


def _identity(x):
    return x


[docs] def validate_json( data: dict, process_fn: Callable = _identity, strictness: Optional[int] = None, ): """ Validate JSON using the Telescope Model schema. The process_fn argument can be used to process semantically correct but schematically invalid Python to something equivalent but valid, e.g., to convert a list of Python tuples to a list of lists. :param data: Dict containing parsed object values :param process_fn: data processing function called before validation :param strictness: strictness level to be used :return: None in the case of valid data """ interface = data.get("interface", None) # TODO: This fails 'open' instead of failing 'closed', if the # caller is requesting strict validation and we can't even tell # what interface to validate against, that should be an error. if interface: JsonSchema.validate_schema( interface, process_fn(data), strictness=strictness )