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

TMSS-250: dd a to the json doc if needed

parent a6283299
No related branches found
No related tags found
1 merge request!295Resolve TMSS-250
...@@ -103,6 +103,12 @@ def get_default_json_object_for_schema(schema: str) -> dict: ...@@ -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: 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''' '''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) 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) get_validator_for_schema(schema, add_defaults=True).validate(copy_of_json_object)
return copy_of_json_object return copy_of_json_object
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment