Skip to content

Commit a5af900

Browse files
Merge pull request #66 from ekonstantinidis/ignore-format
Exclude Endpoints with a <format> parameter
2 parents e3a3aac + bdef22a commit a5af900

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

rest_framework_docs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.6'
1+
__version__ = '0.0.7'

rest_framework_docs/api_docs.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ def get_all_view_names(self, urlpatterns, parent_pattern=None):
2020
if isinstance(pattern, RegexURLResolver):
2121
parent_pattern = None if pattern._regex == "^" else pattern
2222
self.get_all_view_names(urlpatterns=pattern.url_patterns, parent_pattern=parent_pattern)
23-
elif isinstance(pattern, RegexURLPattern) and self._is_drf_view(pattern):
23+
elif isinstance(pattern, RegexURLPattern) and self._is_drf_view(pattern) and not self._is_format_endpoint(pattern):
2424
api_endpoint = ApiEndpoint(pattern, parent_pattern)
2525
self.endpoints.append(api_endpoint)
2626

2727
def _is_drf_view(self, pattern):
28-
# Should check whether a pattern inherits from DRF's APIView
28+
"""
29+
Should check whether a pattern inherits from DRF's APIView
30+
"""
2931
return hasattr(pattern.callback, 'cls') and issubclass(pattern.callback.cls, APIView)
3032

33+
def _is_format_endpoint(self, pattern):
34+
"""
35+
Exclude endpoints with a "format" parameter
36+
"""
37+
return '?P<format>' in pattern._regex
38+
3139
def get_endpoints(self):
3240
return self.endpoints

0 commit comments

Comments
 (0)