Skip to content
Snippets Groups Projects
Commit 122b16a6 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-272: added validate_json_against_its_schema

parent c1e991fd
No related branches found
No related tags found
1 merge request!213Resolve TMSS-272
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment