Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated version of FastAPI (migrate to Pydantic2 and others) #448

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
validator
Signed-off-by: Lucas ONeil <lucasoneil@gmail.com>
loneil committed Mar 27, 2024
commit dbcf95f6356335cf463ec229ac68fe689aa4191c
7 changes: 4 additions & 3 deletions oidc-controller/api/core/models.py
Original file line number Diff line number Diff line change
@@ -4,15 +4,16 @@
from bson import ObjectId
from pydantic import BaseModel, ConfigDict, Field
from pyop.userinfo import Userinfo
from pydantic_core import core_schema


class PyObjectId(ObjectId):
@classmethod
def __get_validators__(cls):
yield cls.validate
def __get_pydantic_core_schema__(cls, source_type, handler) -> core_schema.CoreSchema:
return core_schema.general_plain_validator_function(cls.validate)

@classmethod
def validate(cls, v):
def validate(cls, v, info):
if not ObjectId.is_valid(v):
raise ValueError("Invalid objectid")
return ObjectId(v)