diff --git a/LCS/PyCommon/json_utils.py b/LCS/PyCommon/json_utils.py index 232ba7841c4d588378ab01fb192d8d25b59577bc..4b84ad903e6e0510240743901ba4b9ec7397fb49 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