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

Fix pydantic field and model validator #427

Merged
merged 1 commit into from
Sep 21, 2024
Merged
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
11 changes: 6 additions & 5 deletions backend/app/admin/schema/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime

from pydantic import ConfigDict, EmailStr, Field, HttpUrl, model_validator
from typing_extensions import Self

from backend.app.admin.schema.dept import GetDeptListDetails
from backend.app.admin.schema.role import GetRoleListDetails
Expand All @@ -21,21 +22,21 @@ class AuthLoginParam(AuthSchemaBase):

class RegisterUserParam(AuthSchemaBase):
nickname: str | None = None
email: EmailStr = Field(..., example='[email protected]')
email: EmailStr = Field(..., examples=['[email protected]'])


class AddUserParam(AuthSchemaBase):
dept_id: int
roles: list[int]
nickname: str | None = None
email: EmailStr = Field(..., example='[email protected]')
email: EmailStr = Field(..., examples=['[email protected]'])


class UserInfoSchemaBase(SchemaBase):
dept_id: int | None = None
username: str
nickname: str
email: EmailStr = Field(..., example='[email protected]')
email: EmailStr = Field(..., examples=['[email protected]'])
phone: CustomPhoneNumber | None = None


Expand Down Expand Up @@ -80,15 +81,15 @@ class GetCurrentUserInfoDetail(GetUserInfoListDetails):
roles: list[GetRoleListDetails] | list[str] | None = None

@model_validator(mode='after')
def handel(self, values):
def handel(self) -> Self:
"""处理部门和角色"""
dept = self.dept
if dept:
self.dept = dept.name # type: ignore
roles = self.roles
if roles:
self.roles = [role.name for role in roles] # type: ignore
return values
return self


class CurrentUserIns(GetUserInfoListDetails):
Expand Down
3 changes: 2 additions & 1 deletion backend/app/generator/schema/gen_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime

from pydantic import ConfigDict, Field, model_validator
from typing_extensions import Self

from backend.app.generator.schema.gen_model import GetGenModelListDetails
from backend.common.schema import SchemaBase
Expand All @@ -21,7 +22,7 @@ class GenBusinessSchemaBase(SchemaBase):
remark: str | None = None

@model_validator(mode='after')
def check_schema_name(self):
def check_schema_name(self) -> Self:
if self.schema_name is None:
self.schema_name = self.table_name_en
return self
Expand Down