Skip to content
This repository was archived by the owner on Jan 11, 2021. It is now read-only.

Stable/0.3.x: Fix @api_view wrapper detection on DRF 3.4.7+ #654

Open
wants to merge 1 commit into
base: stable/0.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions rest_framework_swagger/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,17 @@ def wrapper_to_func(wrapper):

def func_to_wrapper(func):
return func.cls


def is_api_view_wrapper(wrapper):
try:
noms = wrapper.http_method_names
handlers = [getattr(wrapper, m) for m in noms if m != 'options']
except AttributeError:
return False
if not handlers or handlers.count(handlers[0]) != len(handlers):
return False
code = six.get_function_code(handlers[0])
return (code.co_filename.endswith('decorators.py') and
code.co_name == 'handler' and
code.co_freevars == ('func',))
3 changes: 2 additions & 1 deletion rest_framework_swagger/docgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
get_primitive_type
)
from .compat import OrderedDict
from .decorators import is_api_view_wrapper


class DocumentationGenerator(object):
Expand Down Expand Up @@ -59,7 +60,7 @@ def get_introspector(self, api, apis):
path = api['path']
pattern = api['pattern']
callback = api['callback']
if callback.__module__ == 'rest_framework.decorators':
if is_api_view_wrapper(callback):
return WrappedAPIViewIntrospector(callback, path, pattern, self.user)
elif issubclass(callback, viewsets.ViewSetMixin):
patterns = [a['pattern'] for a in apis
Expand Down