Skip to content
Snippets Groups Projects
Commit ae694da6 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

FIX(validator): patches are applied recursively to match substructure of records

parent 5f84d8fd
No related branches found
No related tags found
2 merge requests!217TST: Make NamedTemporaryFiles Windows-compatible,!201Validator that checks created records using a json schema
......@@ -71,25 +71,20 @@ def representer_ordereddict(dumper, data):
return dumper.represent_data(dict(data))
def convert_record(record: db.Record):
def apply_schema_patches(pobj: dict):
"""
Convert a record into a form suitable for validation with jsonschema.
Uses high_level_api.convert_to_python_object
Changes applied:
- properties are moved vom subitem "proeprties" to top-level.
- The following keys are deleted: parents, role, name, description, metadata, properties
Arguments:
----------
record: db.Record
The record that is supposed to be converted.
"""
pobj = convert_to_python_object(record).serialize()
if "properties" not in pobj:
# this is probably a file
return pobj
for prop in pobj["properties"]:
pobj[prop] = pobj["properties"][prop]
if isinstance(pobj["properties"][prop], dict):
pobj[prop] = apply_schema_patches(pobj["properties"][prop])
else:
pobj[prop] = pobj["properties"][prop]
for keyd in ("parents", "role", "name",
"description", "metadata", "properties"):
......@@ -99,6 +94,23 @@ def convert_record(record: db.Record):
return pobj
def convert_record(record: db.Record):
"""
Convert a record into a form suitable for validation with jsonschema.
Uses high_level_api.convert_to_python_object
Afterwards apply_schema_patches is called recursively to refactor the dictionary
to match the current form of the jsonschema.
Arguments:
----------
record: db.Record
The record that is supposed to be converted.
"""
pobj = convert_to_python_object(record).serialize()
return apply_schema_patches(pobj)
def validate(records: list[db.Record], schemas: list[dict]) -> list[tuple[bool, list]]:
"""
Validate a list of records against a list of possible JSON schemas.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment