File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import re
1313import asyncio
1414import traceback
15- from typing import List , Union , Optional
15+ from typing import List , Union , Optional , Any
1616from datetime import datetime
1717from contextlib import asynccontextmanager
1818from fastapi import (
@@ -82,8 +82,22 @@ async def lifespan(app: FastAPI): # pylint: disable=redefined-outer-name
8282auth = Authentication (token_url = "user/login" )
8383pubsub = None # pylint: disable=invalid-name
8484
85+
86+ class CustomObjectId (PydanticObjectId ):
87+ @classmethod
88+ def __get_pydantic_json_schema__ (cls , core_schema : Any , handler : GetCoreSchemaHandler ) -> dict [str , Any ]:
89+ json_schema = handler (core_schema )
90+ # Indicate that this field should be treated like a string
91+ # with a pattern matching a 24-character hex string
92+ json_schema .update ({
93+ "type" : "string" ,
94+ "pattern" : "^[0-9a-fA-F]{24}$"
95+ })
96+ return json_schema
97+
98+
8599auth_backend = auth .get_user_authentication_backend ()
86- fastapi_users_instance = FastAPIUsers [User , PydanticObjectId ](
100+ fastapi_users_instance = FastAPIUsers [User , CustomObjectId ](
87101 get_user_manager ,
88102 [auth_backend ],
89103)
You can’t perform that action at this time.
0 commit comments