Skip to content

Commit

Permalink
Add "map" model
Browse files Browse the repository at this point in the history
  • Loading branch information
4c0n committed Aug 28, 2024
1 parent 312e594 commit c62ebd3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pydantic_jsonlogic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ class Filter(BaseJSONLogicOperation):
]


class Map(BaseJSONLogicOperation): ...
class Map(BaseJSONLogicOperation):
map: tuple[
# An array or an operation that produces an array
Union[list[Any], Var, Missing, MissingSome, If, Merge, Filter, "Map"],
# The operation to be performed on each element of the array
BaseJSONLogicOperation,
]
13 changes: 13 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
LessThan,
LessThanOrEqual,
Log,
Map,
Max,
Merge,
Min,
Expand Down Expand Up @@ -493,3 +494,15 @@ def test_if(json: str) -> None:
)
def test_filter(json: str) -> None:
Filter.model_validate_json(json)


@pytest.mark.parametrize(
"json",
[
'{"map":[{"var":"integers"}, {"*":[{"var":""},2]}]}',
'{"map":[{"var":"integers"}, {"*":[{"var":""},2]}]}',
'{"map":[{"var":"desserts"}, {"var":"qty"}]}',
],
)
def test_map(json: str) -> None:
Map.model_validate_json(json)

0 comments on commit c62ebd3

Please sign in to comment.