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:
martincolladofab
2020-06-27 17:19:53 +02:00
committed by GitHub
parent 1f3bb524ae
commit efad0e0fef
12 changed files with 25 additions and 23 deletions

View File

@@ -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