Skip to content

Commit b85a92d

Browse files
author
Emmanouil Konstantinidis
committed
Exclude Endpoints with a <format> parameter
1 parent e3a3aac commit b85a92d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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)