Skip to content

Commit

Permalink
Merge branch 'main' into main-update-submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamier authored Jan 23, 2025
2 parents e5b7ebc + c08d4f9 commit da50d7e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/erc7730/model/paths/path_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]})

0 comments on commit da50d7e

Please sign in to comment.