From c5f20de78eeb812fbc3bde341f667228935bc64c Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Fri, 4 Dec 2020 08:30:45 +0100 Subject: [PATCH] TMSS-250: dd a to the json doc if needed --- LCS/PyCommon/json_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/LCS/PyCommon/json_utils.py b/LCS/PyCommon/json_utils.py index 232ba7841c4..4b84ad903e6 100644 --- a/LCS/PyCommon/json_utils.py +++ b/LCS/PyCommon/json_utils.py @@ -103,6 +103,12 @@ def get_default_json_object_for_schema(schema: str) -> dict: def add_defaults_to_json_object_for_schema(json_object: dict, schema: str) -> dict: '''return a copy of the json object with defaults filled in according to the schema for all the missing properties''' copy_of_json_object = deepcopy(json_object) + + # add a $schema to the json doc if needed + if '$schema' not in copy_of_json_object and '$id' in schema: + copy_of_json_object['$schema'] = schema['$id'] + + # run validator, which populates the properties with defaults. get_validator_for_schema(schema, add_defaults=True).validate(copy_of_json_object) return copy_of_json_object -- GitLab