2525from boto3 .dynamodb .conditions import Attr
2626from fastapi_users .db .base import BaseUserDatabase
2727from fastapi_users .models import ID , OAP , UP
28+ from pydantic import BaseModel , ConfigDict , Field
2829
2930from fastapi_users_db_dynamodb ._aioboto3_patch import * # noqa: F403
3031from fastapi_users_db_dynamodb .generics import GUID
3435UUID_ID = uuid .UUID
3536
3637
37- class DynamoDBBaseUserTable (Generic [ID ]):
38+ class DynamoDBBaseUserTable (BaseModel , Generic [ID ]):
3839 """Base user table schema for DynamoDB."""
3940
41+ model_config = ConfigDict (arbitrary_types_allowed = True )
42+
4043 __tablename__ = "user"
4144
4245 if TYPE_CHECKING :
4346 id : ID
44- email : str
45- hashed_password : str
46- is_active : bool
47- is_superuser : bool
48- is_verified : bool
47+ email : str = Field (..., description = "The email of the user" )
48+ hashed_password : str = Field (..., description = "The hashed password of the user" )
49+ is_active : bool = Field (
50+ default = True , description = "Whether the user is marked as active in the database"
51+ )
52+ is_superuser : bool = Field (
53+ default = False , description = "Whether the user has admin rights"
54+ )
55+ is_verified : bool = Field (
56+ default = False , description = "Whether the user has verified their email"
57+ )
4958
5059
5160class DynamoDBBaseUserTableUUID (DynamoDBBaseUserTable [UUID_ID ]):
52- id : UUID_ID
61+ id : UUID_ID = Field ( default_factory = uuid . uuid4 , description = "The ID for the user" )
5362
5463
5564class DynamoDBBaseOAuthAccountTable (Generic [ID ]):
@@ -59,18 +68,27 @@ class DynamoDBBaseOAuthAccountTable(Generic[ID]):
5968
6069 if TYPE_CHECKING :
6170 id : ID
62- oauth_name : str
63- access_token : str
64- expires_at : int | None
65- refresh_token : str | None
66- account_id : str
67- account_email : str
68- user_id : ID
71+ oauth_name : str = Field (..., description = "The name of the OAuth social provider" )
72+ access_token : str = Field (
73+ ..., description = "The access token linked with the OAuth account"
74+ )
75+ expires_at : int | None = Field (
76+ default = None , description = "The timestamp at which this account expires"
77+ )
78+ refresh_token : str | None = Field (
79+ default = None , description = "The refresh token associated with this OAuth account"
80+ )
81+ account_id : str = Field (..., description = "The ID of this OAuth account" )
82+ account_email : str = Field (
83+ ..., description = "The email associated with this OAuth account"
84+ )
6985
7086
7187class DynamoDBBaseOAuthAccountTableUUID (DynamoDBBaseUserTable [UUID_ID ]):
72- id : UUID_ID
73- user_id : GUID
88+ id : UUID_ID = Field (
89+ default_factory = uuid .uuid4 , description = "The ID for the OAuth account"
90+ )
91+ user_id : GUID = Field (..., description = "The user ID this OAuth account belongs to" )
7492
7593
7694class DynamoDBUserDatabase (Generic [UP , ID ], BaseUserDatabase [UP , ID ]):
0 commit comments