Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<branch> pydantic v2 #659

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/arguments-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ For example:
```python
class CustomValidationModel(BaseModel):
custom_int: int
custom_arg: Optional[int]
custom_arg: int | None = None

@validator('custom_arg')
@field_validator('custom_arg')
@classmethod
def validate_custom_arg(cls, value):
assert value % 5 == 0
Expand Down
4 changes: 2 additions & 2 deletions frontik/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def get_validated_argument(
if default is not _ARG_DEFAULT and default is not None:
try:
params = {validator: default}
validated_default = self._validation_model(**params).dict().get(validator)
validated_default = self._validation_model(**params).model_dump().get(validator)
except ValidationError:
raise DefaultValueError()
else:
Expand All @@ -247,7 +247,7 @@ def get_validated_argument(

try:
params = {validator: value}
validated_value = self._validation_model(**params).dict().get(validator)
validated_value = self._validation_model(**params).model_dump().get(validator)
except ValidationError:
if default is _ARG_DEFAULT:
raise TypedArgumentError(http.client.BAD_REQUEST, f'"{name}" argument is invalid')
Expand Down
20 changes: 10 additions & 10 deletions frontik/validator.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
from enum import Enum

from pydantic import BaseModel, validator
from pydantic import BaseModel, field_validator


class Validators(Enum):
BOOLEAN = 'boolean'
STRING = 'string'
INTEGER = 'integer'
FLOAT = 'float'
FLOAT = 'float_'
LIST_INT = 'list_int'
LIST_STR = 'list_str'
PATH_SAFE_STRING = 'path_safe_string'


class BaseValidationModel(BaseModel):
boolean: bool | None
string: str | None
integer: int | None
float: float | None
list_int: list[int] | None
list_str: list[str] | None
path_safe_string: str | None
boolean: bool | None = None
string: str | None = None
integer: int | None = None
float_: float | None = None
list_int: list[int] | None = None
list_str: list[str] | None = None
path_safe_string: str | None = None

@validator('path_safe_string', pre=True)
@field_validator('path_safe_string', mode='before')
@classmethod
def check_path_safe_string(cls, value):
assert isinstance(value, str)
Expand Down
Loading