mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2026-03-13 07:49:55 +08:00
fix "Swagger issue for endpoints register & update" (#233)
* fix: Change on the inheritance model, according to the documentation for the request body parameters. #171 * fix: Changes on the documentation examples to fix the inheritance problem when passing the User class (for create or update only passing the pydantic one) #171 * fix: Changes on the documentation examples to fix the inheritance problem when passing the User class (for create or update only passing the pydantic one) #171 * Put back inheritance on update model and factorize create_update_dict methods Co-authored-by: François Voron <fvoron@gmail.com>
This commit is contained in:
@@ -4,7 +4,18 @@ from typing import List, Optional, TypeVar
|
||||
from pydantic import UUID4, BaseModel, EmailStr, validator
|
||||
|
||||
|
||||
class BaseUser(BaseModel):
|
||||
class CreateUpdateDictModel(BaseModel):
|
||||
def create_update_dict(self):
|
||||
return self.dict(
|
||||
exclude_unset=True,
|
||||
exclude={"id", "is_superuser", "is_active", "oauth_accounts"},
|
||||
)
|
||||
|
||||
def create_update_dict_superuser(self):
|
||||
return self.dict(exclude_unset=True, exclude={"id"})
|
||||
|
||||
|
||||
class BaseUser(CreateUpdateDictModel):
|
||||
"""Base User model."""
|
||||
|
||||
id: Optional[UUID4] = None
|
||||
@@ -16,17 +27,8 @@ class BaseUser(BaseModel):
|
||||
def default_id(cls, v):
|
||||
return v or uuid.uuid4()
|
||||
|
||||
def create_update_dict(self):
|
||||
return self.dict(
|
||||
exclude_unset=True,
|
||||
exclude={"id", "is_superuser", "is_active", "oauth_accounts"},
|
||||
)
|
||||
|
||||
def create_update_dict_superuser(self):
|
||||
return self.dict(exclude_unset=True, exclude={"id"})
|
||||
|
||||
|
||||
class BaseUserCreate(BaseUser):
|
||||
class BaseUserCreate(CreateUpdateDictModel):
|
||||
email: EmailStr
|
||||
password: str
|
||||
|
||||
|
||||
Reference in New Issue
Block a user