diff --git a/src/caosadvancedtools/table_json_conversion/convert.py b/src/caosadvancedtools/table_json_conversion/convert.py index cec320bb7899cb761f056d46496dd34621fb6a47..7a3d63a2444d09f0c9f695edfa8fd6865593f62e 100644 --- a/src/caosadvancedtools/table_json_conversion/convert.py +++ b/src/caosadvancedtools/table_json_conversion/convert.py @@ -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)