modified decorator doesn't work in django/python

I’m writing a decorator that works approximately to the api version a user uses. So thus, I want to have something like, but then that the response serializer depends on the api version the user uses:

# noinspection PyMethodMayBeStatic @swagger_auto_schema(     responses={         200: openapi.Response(             _(                 "Successfully fetched the array of all sites where the user belongs to."             ),             response_serializer,         )     }, ) def list(self, request, *args, **kwargs):     """     Return all sites where the user is part of.     """ 

My view and decorator function:

class SiteView(viewsets.ModelViewSet):     """     API endpoint that allows sites to be viewed or edited     """      pagination_class = StandardPagination      queryset = Site.objects.all()      def swagger_auto_schema(f):         def wrap(self, *args, **kwargs):              serializer = self.get_response_serializer()             f.responses = (                 {                     200: openapi.Response(                         _(                             "Successfully fetched the array of all sites where the user belongs to."                         ),                         serializer,                     )                 },             )             ret = f(self, *args, **kwargs)             return ret          return wrap      def get_response_serializer(self):         if self.request.version == "v2":             return AdminSiteSerializer         else:             return SiteSerializer      def get_permissions(self):         return (IsAuthenticated(),)      def get_serializer_class(self):         if self.request and self.request.method == "POST":             return SiteCreationSerializer         return SiteSerializer      # noinspection PyMethodMayBeStatic     @swagger_auto_schema     def list(self, request, *args, **kwargs):         """         Return all sites where the user is part of.         """ 

I don’t get any errors. But it does just not work, the documentation on swagger doesn’t change

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.