From acd1e3b4070197256630f6d405485e50d7d8dee9 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Sat, 6 Sep 2025 23:22:31 +0300 Subject: [PATCH] Features: 1) Add request schema using `UserSerializer` for user creation endpoint; 2) Implement validation for `attributes` in user serializer, ensuring it's a dictionary and requiring `business_identificator` for business accounts; Fixes: None; Extra: None; --- vibes_auth/docs/drf/viewsets.py | 1 + vibes_auth/serializers.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/vibes_auth/docs/drf/viewsets.py b/vibes_auth/docs/drf/viewsets.py index 0b74cd97..e8cead2b 100644 --- a/vibes_auth/docs/drf/viewsets.py +++ b/vibes_auth/docs/drf/viewsets.py @@ -14,6 +14,7 @@ from vibes_auth.serializers import ( USER_SCHEMA = { "create": extend_schema( summary=_("create a new user"), + request=UserSerializer, responses={status.HTTP_201_CREATED: UserSerializer, **BASE_ERRORS}, ), "retrieve": extend_schema( diff --git a/vibes_auth/serializers.py b/vibes_auth/serializers.py index 9f6f59cb..0541774f 100644 --- a/vibes_auth/serializers.py +++ b/vibes_auth/serializers.py @@ -94,6 +94,11 @@ class UserSerializer(ModelSerializer): return instance def validate(self, attrs): + if "attributes" in attrs: + if not isinstance(attrs["attributes"], dict): + raise ValidationError(_("attributes must be a dictionary")) + if attrs["attributes"].get("is_business") and not attrs["attributes"].get("business_identificator"): + raise ValidationError(_("business identificator is required when registering as a business")) if "password" in attrs: validate_password(attrs["password"]) if not compare_digest(attrs["password"], attrs["confirm_password"]):