Skip to content

Commit 036fe14

Browse files
author
Emmanouil Konstantinidis
committed
Check if each view inherits from DRF's ApiView
1 parent 09b9e94 commit 036fe14

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

drfdocs/api_docs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.conf import settings
22
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern
33
from drfdocs.api_endpoint import ApiEndpoint
4+
from rest_framework.views import APIView
45

56

67
class ApiDocumentation(object):
@@ -16,13 +17,15 @@ def get_all_view_names(self, urlpatterns, parent_pattern=None):
1617
for pattern in urlpatterns:
1718
if isinstance(pattern, RegexURLResolver) and (pattern.app_name not in self.excluded_apps):
1819
self.get_all_view_names(urlpatterns=pattern.url_patterns, parent_pattern=pattern)
19-
elif isinstance(pattern, RegexURLPattern) and (pattern.callback.__name__ not in self.excluded_endpoints):
20+
elif isinstance(pattern, RegexURLPattern) and (pattern.callback.__name__ not in self.excluded_endpoints) and self._is_drf_view(pattern):
2021
api_endpoint = ApiEndpoint(pattern, parent_pattern)
2122
self.endpoints.append(api_endpoint)
2223

23-
def _filter_drf_views(self, endpoints):
24-
# Should keep only the endpoints with views that inherit from DRF's APIView
25-
pass
24+
def _is_drf_view(self, pattern):
25+
# Should check whether a pattern inherits from DRF's APIView
26+
if (hasattr(pattern.callback, 'cls') and issubclass(pattern.callback.cls, APIView)):
27+
return True
28+
return False
2629

2730
def get_endpoints(self):
2831
return self.endpoints

drfdocs/api_endpoint.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from django.contrib.admindocs.views import simplify_regex
2-
from rest_framework.views import APIView
32

43

54
class ApiEndpoint(object):
@@ -11,11 +10,3 @@ def __init__(self, pattern, parent_pattern=None):
1110
self.url_name = pattern.name
1211
self.regex = simplify_regex(pattern._regex)
1312
self.view_name = pattern.callback.__name__
14-
# self._get_api_callback(pattern)
15-
16-
def _get_api_callback(self, pattern):
17-
"""
18-
Verifies that pattern callback is a subclass of APIView, and returns the class
19-
"""
20-
if (hasattr(pattern.callback, 'cls') and issubclass(pattern.callback.cls, APIView)):
21-
return pattern.callback.cls

0 commit comments

Comments
 (0)