Skip to content

Commit

Permalink
Add universal JSONLogic type, which is essentially a union of all ava…
Browse files Browse the repository at this point in the history
…ilable operations (#10)
  • Loading branch information
4c0n authored Sep 5, 2024
1 parent be14668 commit 331529a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pydantic_jsonlogic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,42 @@ class Some(BaseJSONLogicOperation):
# Something that produces a truthy or falsy result
bool | BaseJSONLogicOperation,
]


JSONLogic = (
Add
| All
| And
| Cat
| Divide
| Equals
| Filter
| GreaterThan
| GreaterThanOrEqual
| If
| In
| LessThan
| LessThanOrEqual
| Log
| Map
| Max
| Merge
| Min
| Max
| Missing
| MissingSome
| Modulo
| Multiply
| None_
| Not
| NotEquals
| NotNot
| Or
| Reduce
| Some
| StrictEquals
| StrictNotEquals
| Substr
| Subtract
| Var
)
14 changes: 14 additions & 0 deletions tests/test_model_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pydantic import BaseModel

from pydantic_jsonlogic import All, JSONLogic


class SomeModel(BaseModel):
json_logic: JSONLogic


def test_model_integration() -> None:
model = SomeModel.model_validate_json(
'{"json_logic": {"all":[{"var":"integers"}, {">=":[{"var":""}, 1]}]}}'
)
assert isinstance(model.json_logic, All)

0 comments on commit 331529a

Please sign in to comment.