Skip to content

Commit

Permalink
Add "cat" model
Browse files Browse the repository at this point in the history
  • Loading branch information
4c0n committed Aug 27, 2024
1 parent ce88ee3 commit d49c091
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pydantic_jsonlogic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@ class In(BaseModel):
model_config = ConfigDict(strict=True)

in_: tuple[str, list[str] | str] = Field(validation_alias="in")


class Cat(BaseModel):
model_config = ConfigDict(strict=True)

cat: int | str | list[int | str]
16 changes: 16 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pydantic_jsonlogic import (
Add,
Cat,
Divide,
Equals,
GreaterThan,
Expand Down Expand Up @@ -284,3 +285,18 @@ def test_modulo(json: str) -> None:
)
def test_in(json: str) -> None:
In.model_validate_json(json)


@pytest.mark.parametrize(
"json",
[
'{"cat":"ice"}',
'{"cat":["ice"]}',
'{"cat":["ice","cream"]}',
'{"cat":[1,2]}',
'{"cat":["Robocop",2]}',
'{"cat":["we all scream for ","ice","cream"]}',
],
)
def test_cat(json: str) -> None:
Cat.model_validate_json(json)

0 comments on commit d49c091

Please sign in to comment.