diff --git a/SAS/TMSS/src/tmss/tmssapp/validation.py b/SAS/TMSS/src/tmss/tmssapp/validation.py index 21785954c6326e3e20f496e3c23706d829e0f7c1..0639bb2cc40cecf0c940fd7a117394f02db31055 100644 --- a/SAS/TMSS/src/tmss/tmssapp/validation.py +++ b/SAS/TMSS/src/tmss/tmssapp/validation.py @@ -4,13 +4,18 @@ from jsonschema import Draft6Validator, RefResolver import os from lofar.sas.tmss.tmss.exceptions import * from lofar.common.json_utils import add_defaults_to_json_object_for_schema as json_utils_add_defaults_to_json - +import requests BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TMSS_SCHEMA_PATH = BASE_DIR + "/tmssapp/schemas/" TMSS_COMMON_BASE_SCHEMA = "base.json" # TODO: validation is not the correct name any more rename to schema.py or schema_utils.py ? +def validate_json_against_its_schema(json_object: dict): + '''validate the give json object against its own schema (the URI/URL that its propery $schema points to)''' + schema = json_object['$schema'] + return validate_json_against_schema(json_object, requests.get(schema).text) + def validate_json_against_schema(json_string: str, schema: str): '''validate the given json_string against the given schema. If no exception if thrown, then the given json_string validates against the given schema.