diff --git a/LCS/PyCommon/json_utils.py b/LCS/PyCommon/json_utils.py index 4051c3e87e172e97d55b91dc35965e5907e5b83a..dadbf88a7df2abda69552a51037552c43a8e69d5 100644 --- a/LCS/PyCommon/json_utils.py +++ b/LCS/PyCommon/json_utils.py @@ -488,6 +488,12 @@ def validate_json_object_with_schema(json_object, schema, add_defaults: bool=Fal """ Validate the given json_object with schema """ + if '$schema' in json_object and '$id' in schema: + object_schema_id = json_object['$schema'].partition('#')[0].rstrip('/').rstrip('ref_resolved').rstrip('/') + schema_id = schema['$id'].partition('#')[0].rstrip('/').rstrip('ref_resolved').rstrip('/') + if object_schema_id != schema_id: + raise JSONError("json_object refers to different $schema='%s' and cannot be compared to the schema with $id='%s'" % (object_schema_id, schema_id)) + get_validator_for_schema(schema, add_defaults=add_defaults).validate(json_object) return json_object diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py index 7bc887449574b66720834032dc49accb760a4d95..9ce0ca75006c049f5386c4aa3478f9a95034f109 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py @@ -260,10 +260,10 @@ class AbstractSchemaTemplate(AbstractTemplate): # this template's schema has a schema of its own (usually the draft-06 meta schema). Validate it. validate_json_against_its_schema(self.schema, cache=TemplateSchemaMixin._schema_cache, max_cache_age=TemplateSchemaMixin._MAX_SCHEMA_CACHE_AGE) - def validate_document(self, json_doc: typing.Union[str, dict]) -> bool: - '''validate the given json_doc against the template's schema - If no exception if thrown, then the given json_string validates against the given schema. - :raises SchemaValidationException if the json_string does not validate against the schema ''' + def validate_document_against_schema(self, json_doc: typing.Union[str, dict]): + '''validate the given json_doc against this template's schema + If no exception if thrown, then the given json_doc validates. + :raises SchemaValidationException if the json_doc does not validate against this template's schema''' validate_json_against_schema(json_doc, self.schema, cache=TemplateSchemaMixin._schema_cache, max_cache_age=TemplateSchemaMixin._MAX_SCHEMA_CACHE_AGE) @property