diff --git a/src/erc7730/model/paths/path_schemas.py b/src/erc7730/model/paths/path_schemas.py index 188bf32..472ff36 100644 --- a/src/erc7730/model/paths/path_schemas.py +++ b/src/erc7730/model/paths/path_schemas.py @@ -190,19 +190,22 @@ def data_path_to_schema_path(path: DataPath) -> DataPath: """ Convert a data path to a schema path. - Example: #.foo.[].[-2].[1:5].bar -> #.foo.[].[].[].bar + Example: #.foo.[].[-2].bar.[1:5] -> #.foo.[].[].bar :param path: data path :return: schema path """ - def to_schema(element: DataPathElement) -> DataPathElement: + def to_schema(element: DataPathElement) -> DataPathElement | None: match element: case Field() as f: return f - case Array() | ArrayElement() | ArraySlice(): + case Array() | ArrayElement(): return Array() + # TODO: Spec also allows slicing on array type, but for now it is only used on primitive types + case ArraySlice(): + return None case _: assert_never(element) - return path.model_copy(update={"elements": [to_schema(e) for e in path.elements]}) + return path.model_copy(update={"elements": [to_schema(e) for e in path.elements if to_schema(e) is not None]})