Skip to content
Snippets Groups Projects
Commit d9be5792 authored by I. Nüske's avatar I. Nüske
Browse files

MNT: Add allOf, oneOf handling to _validate_jsonschema

parent fef66b62
Branches
Tags
2 merge requests!138Release 0.14.0,!129Enable validation in table_json_conversion.convert.to_dict for use in XLSX-converter
Pipeline #60781 passed
......@@ -154,20 +154,22 @@ class ForeignError(KeyError):
def _validate_jsonschema(instance, schema):
# Checks whether a key: value pair is in the given schema or a direct
# subschema (anyOf) ToDo: How to treat allOf and oneOf?
# Checks whether a key: value pair is in the given schema or fulfills the
# criteria of a direct subschema (anyOf, allOf, oneOf)
def in_schema(key, val, schema):
if schema.get(key, None) == val:
return True
if 'anyOf' in schema:
return any([in_schema(key, val, sub) for sub in schema['anyOf']])
if 'allOf' in schema:
return all([in_schema(key, val, sub) for sub in schema['allOf']])
if 'oneOf' in schema:
return [in_schema(key, val, sub) for sub in schema['oneOf']].count(True) == 1
return False
# Removes Key: None and datetime instances from nested dicts and lists of
# any depth. Key: None is currently valid as there is no 'obligatory with
# value', and datetime cannot be checked by jsonschema.
# ToDo: Is ID: None also valid?
def remove_incompatible_values(it, schema):
if isinstance(it, list):
schema = schema.get('items', schema)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment