marcgibbons/django-rest-swagger — pull request #90 by fmaillard (2014-06-17 09:48:54+00:00)
Title: Add the possibility to use a custom method introspector class for any view.

In a project, I have implemented custom additional http methods, and the automatically generated responseClass and method parameters did not suit me. To work around this, I wrote a patch to be able to use a custom APIViewMethodIntrospector for any view.

Indeed, my need was very specific, yet the solution is quite generic, so i thought it might be worth merging.

As an exemple, if you have a UserList view for which you have a specific need :

class UserList(generics.ListCreateAPIView):
def get_method_introspector_class(self):
return UserMethodIntrospector

from rest_framework_swagger.introspectors import APIViewMethodIntrospector
class TestMethodIntrospector(APIViewMethodIntrospector):
def get_parameters(self):
if self.get_http_method() != 'CUSTOM':
return super(TestMethodIntrospector, self).get_parameters()

params = []
# do something with params
return params

def get_response_class(self):
if self.get_http_method() != 'CUSTOM':
return super(TestMethodIntrospector, self).get_response_class()

# return a custom reponse class
return None