From 49c1e0d43561eb86c96f0e5546748f350f3afd91 Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Thu, 2 May 2024 15:21:35 +0200
Subject: [PATCH] MAINT: Moved get_subschema to xlsx_utils

---
 .../table_json_conversion/convert.py              | 15 +++------------
 .../table_json_conversion/xlsx_utils.py           | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/caosadvancedtools/table_json_conversion/convert.py b/src/caosadvancedtools/table_json_conversion/convert.py
index 02c46bd1..c0601a17 100644
--- a/src/caosadvancedtools/table_json_conversion/convert.py
+++ b/src/caosadvancedtools/table_json_conversion/convert.py
@@ -224,23 +224,14 @@ This includes:
         # Finally: convert to target type
         return self.PARSER[subschema.get("type", "string")](value)
 
-    def _get_subschema(self, path: list[str], schema: Union[dict, list] = None) -> dict:
+    def _get_subschema(self, path: list[str], schema: dict = None) -> dict:
         """Return the sub schema at ``path``."""
         if schema is None:
             schema = self._schema
             assert schema is not None
         assert isinstance(schema, dict)
-        if path:
-            if schema["type"] == "object":
-                next_schema = schema["properties"][path[0]]
-                return self._get_subschema(path=path[1:], schema=next_schema)
-            if schema["type"] == "array":
-                items = schema["items"]
-                if "enum" in items:
-                    return schema
-                next_schema = items["properties"][path[0]]
-                return self._get_subschema(path=path[1:], schema=next_schema)
-        return schema
+
+        return xlsx_utils.get_subschema(path, schema)
 
 
 def _group_foreign_paths(foreign: list[list], common: list[str]) -> list[SimpleNamespace]:
diff --git a/src/caosadvancedtools/table_json_conversion/xlsx_utils.py b/src/caosadvancedtools/table_json_conversion/xlsx_utils.py
index 32ed8552..7cedd391 100644
--- a/src/caosadvancedtools/table_json_conversion/xlsx_utils.py
+++ b/src/caosadvancedtools/table_json_conversion/xlsx_utils.py
@@ -260,6 +260,21 @@ def get_row_type_column_index(sheet: Worksheet):
     raise ValueError("The column which defines row types (COL_TYPE, PATH, ...) is missing")
 
 
+def get_subschema(path: list[str], schema: dict) -> dict:
+    """Return the sub schema at ``path``."""
+    if path:
+        if schema["type"] == "object":
+            next_schema = schema["properties"][path[0]]
+            return get_subschema(path=path[1:], schema=next_schema)
+        if schema["type"] == "array":
+            items = schema["items"]
+            if "enum" in items:
+                return schema
+            next_schema = items["properties"][path[0]]
+            return get_subschema(path=path[1:], schema=next_schema)
+    return schema
+
+
 def get_worksheet_for_path(path: list[str], defining_path_index: dict[str, list[list[str]]]) -> str:
     """Find the sheet name which corresponds to the given path."""
     for sheetname, paths in defining_path_index.items():
-- 
GitLab