Skip to content

Commit

Permalink
generalized
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 30, 2024
1 parent 8239f77 commit df4cfb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from ..emails import LowerCaseEmailStr
from ..users import UserID
from ..utils.common_validators import create__only_one_is_set__root_validator
from ..utils.common_validators import create__check_only_one_is_set__root_validator
from ._base import InputSchema, OutputSchema


Expand Down Expand Up @@ -184,17 +184,13 @@ class GroupUserAdd(InputSchema):
email: LowerCaseEmailStr | None = None

_check_uid_or_email = root_validator(allow_reuse=True)(
create__only_one_is_set__root_validator(["uid", "email"])
create__check_only_one_is_set__root_validator(["uid", "email"])
)
# @root_validator
# @classmethod
# def _check_uid_or_email(cls, values):
# uid, email = values.get("uid"), values.get("email")
# # Ensure exactly one of uid or email is set
# if not (bool(uid is not None) ^ bool(email is not None)):
# msg = f"Either 'uid' or 'email' must be set, but not both. Got {uid=} and {email=}"
# raise ValueError(msg)
# return values

class Config:
schema_extra: ClassVar[dict[str, Any]] = {
"examples": [{"uid": 42}, {"email": "[email protected]"}]
}


class GroupUserUpdate(InputSchema):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def null_or_none_str_to_none_validator(value: Any):
return value


def create__only_one_is_set__root_validator(alternative_field_names: list[str]):
def create__check_only_one_is_set__root_validator(alternative_field_names: list[str]):
"""Ensure exactly one and only one of the alternatives is set
This is useful when you want to give the client alternative
Expand Down

0 comments on commit df4cfb5

Please sign in to comment.