Skip to content
Snippets Groups Projects
Verified Commit 49c1e0d4 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

MAINT: Moved get_subschema to xlsx_utils

parent 4a507ac1
No related branches found
No related tags found
2 merge requests!107Release v0.11.0,!103xlsx -> json conversion
Pipeline #50557 passed
......@@ -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]:
......
......@@ -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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment