diff --git a/src/caosadvancedtools/table_json_conversion/convert.py b/src/caosadvancedtools/table_json_conversion/convert.py index 02c46bd1519878557f1cc8d9df37775ffad096bc..c0601a17e03c9328341698c28b0d00c9c7b58b40 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 32ed8552ce26f0c2245f9739721ba82ed95c12bf..7cedd391087b386c5e0b194301191f2d4881ddf6 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():