Skip to content

Commit

Permalink
Exclude Endpoints with a <format> parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanouil Konstantinidis committed Feb 25, 2016
1 parent e3a3aac commit b85a92d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rest_framework_docs/api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ def get_all_view_names(self, urlpatterns, parent_pattern=None):
if isinstance(pattern, RegexURLResolver):
parent_pattern = None if pattern._regex == "^" else pattern
self.get_all_view_names(urlpatterns=pattern.url_patterns, parent_pattern=parent_pattern)
elif isinstance(pattern, RegexURLPattern) and self._is_drf_view(pattern):
elif isinstance(pattern, RegexURLPattern) and self._is_drf_view(pattern) and not self._is_format_endpoint(pattern):
api_endpoint = ApiEndpoint(pattern, parent_pattern)
self.endpoints.append(api_endpoint)

def _is_drf_view(self, pattern):
# Should check whether a pattern inherits from DRF's APIView
"""
Should check whether a pattern inherits from DRF's APIView
"""
return hasattr(pattern.callback, 'cls') and issubclass(pattern.callback.cls, APIView)

def _is_format_endpoint(self, pattern):
"""
Exclude endpoints with a "format" parameter
"""
return '?P<format>' in pattern._regex

def get_endpoints(self):
return self.endpoints

0 comments on commit b85a92d

Please sign in to comment.