django using drf-spectacular, I cannot customize schema with @extend_schema decorator

62 views Asked by At

I have the following view:

class ReferralCodeList(generics.ListCreateAPIView):
    queryset = ReferralCode.objects.all()
    serializer_class = ReferralCodeSerializer
    
    def get_queryset(self):
        queryset = super().get_queryset()
        queryset = queryset.filter(user=self.request.user)
        return queryset
    
    @extend_schema(
        description='More descriptive text',
    )
    def create(self, request, *args, **kwargs):
        request.data['user'] = request.user.id
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        
        if 'send_mail' in request.data.keys() and \
           request.data['send_mail'] == True:
            send_mail(
                "Your referral code",
                serializer.data['code_str'],
                project_settings.EMAIL_HOST_USER,
                [request.user.email],
                fail_silently=False,
            )
        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data,
                        status=status.HTTP_201_CREATED, headers=headers)

I execute ./manage.py spectacular --color --file schema.yml But I don't see any changes to the view's description. no description for my view When I change the serializer, I see the respective changes in swagger page.

What am I doing wrong? I expect it to work like here https://drf-spectacular.readthedocs.io/en/latest/readme.html

Thanks

Update: when applied to the whole class, the decorator works, but that's not what I want

0

There are 0 answers