From d9be57921accf908adef97de9b576df99525ab04 Mon Sep 17 00:00:00 2001
From: "i.nueske" <i.nueske@indiscale.com>
Date: Tue, 11 Feb 2025 11:18:13 +0100
Subject: [PATCH] MNT: Add allOf, oneOf handling to _validate_jsonschema

---
 src/caosadvancedtools/table_json_conversion/convert.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/caosadvancedtools/table_json_conversion/convert.py b/src/caosadvancedtools/table_json_conversion/convert.py
index cec320bb..7a3d63a2 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)
-- 
GitLab