diff --git a/packages/models-library/src/models_library/api_schemas_webserver/groups.py b/packages/models-library/src/models_library/api_schemas_webserver/groups.py index 13bfe711dfb5..965a597cc800 100644 --- a/packages/models-library/src/models_library/api_schemas_webserver/groups.py +++ b/packages/models-library/src/models_library/api_schemas_webserver/groups.py @@ -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 @@ -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": "foo@email.com"}] + } class GroupUserUpdate(InputSchema): diff --git a/packages/models-library/src/models_library/utils/common_validators.py b/packages/models-library/src/models_library/utils/common_validators.py index baf09445ffe8..98d7f8541257 100644 --- a/packages/models-library/src/models_library/utils/common_validators.py +++ b/packages/models-library/src/models_library/utils/common_validators.py @@ -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