Skip to content

Commit

Permalink
Merge pull request #66 from ekonstantinidis/ignore-format
Browse files Browse the repository at this point in the history
Exclude Endpoints with a <format> parameter
  • Loading branch information
ekonstantinidis committed Feb 25, 2016
2 parents e3a3aac + bdef22a commit a5af900
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rest_framework_docs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.6'
__version__ = '0.0.7'
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 a5af900

Please sign in to comment.