36 lines
986 B
Python
36 lines
986 B
Python
from typing import ClassVar, Literal
|
|
from uuid import UUID
|
|
|
|
from pydantic import BaseModel, ConfigDict, ValidationInfo, field_validator
|
|
|
|
|
|
class Base(BaseModel):
|
|
model_config = ConfigDict(extra="forbid", from_attributes=True)
|
|
|
|
id: UUID
|
|
|
|
|
|
class Health(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
status: Literal["ok"]
|
|
|
|
|
|
class BaseCreate(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
blank_allowed_fields: ClassVar[frozenset[str]] = frozenset({"password"})
|
|
|
|
@field_validator("*", mode="before")
|
|
@classmethod
|
|
def reject_blank_strings(cls, value: object, info: ValidationInfo) -> object:
|
|
if info.field_name in cls.blank_allowed_fields:
|
|
return value
|
|
if isinstance(value, str) and not value.strip():
|
|
raise ValueError("Строка не может состоять только из пробелов")
|
|
return value
|
|
|
|
|
|
class BasePage(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|