Open wasdee opened 4 years ago
for the workaround, i creates 2 class and use the orm to convert them.
class GoogleCredential_Fastapi(BaseModel):
"""
Make for AccessTokenResponse of pub.dartlang.org\oauth2_client-1.4.5\lib\access_token_response.dart
"""
access_token: str
refresh_token: str
scopes: List[str] = Field(alias='scope')
expiration_date: datetime
expires_in: int
token_type: str
http_status_code: int
error: Optional[str] = None
errorDescription: Optional[str] = None
errorUri: Optional[str] = None
@validator('expiration_date')
def convert_to_datetime(cls, value):
if isinstance(value, int):
time = arrow.get(value)
value = time.datetime
return value
class GoogleCredential(MagicModel):
"""
Make for AccessTokenResponse of pub.dartlang.org\oauth2_client-1.4.5\lib\access_token_response.dart
"""
access_token: str
refresh_token: str
scopes: List[str]
expiration_date: datetime
expires_in: int
token_type: str
http_status_code: int
error: Optional[str] = None
errorDescription: Optional[str] = None
errorUri: Optional[str] = None
class Config:
orm_mode = True
@app.post("/users/{user_id}/integrations/google_drive")
def set_google_integration(user_id: str, google_cred: GoogleCredential_Fastapi):
user = User.collection.get(user_id)
user.integrations.google = GoogleCredential.from_orm(google_cred)
user.save()
validate_py(self)
causes error when a variable is using alias i.e.scopes: List[str] = Field(alias='scope')
. This also causes incompatible to use with fastapi. I personally think that the function validateCould be changed to solve this. For example, we could use orm style creation to avoid the error. I still not fully understand the process of the library. please advice. 😂
Error Log
Class Defination