Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to augmented API paths. #108

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions rest_framework_docs/api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ def __init__(self, drf_router=None):
else:
self.get_all_view_names(root_urlconf.urlpatterns)

def get_all_view_names(self, urlpatterns, parent_pattern=None):
def get_all_view_names(self, urlpatterns, ancestors_patterns=None):
if ancestors_patterns is None:
ancestors_patterns = []
for pattern in urlpatterns:
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)
if pattern._regex != "^":
ancestors_patterns.append(pattern)
self.get_all_view_names(urlpatterns=pattern.url_patterns, ancestors_patterns=ancestors_patterns)
if ancestors_patterns:
ancestors_patterns.pop()
elif isinstance(pattern, RegexURLPattern) and self._is_drf_view(pattern) and not self._is_format_endpoint(pattern):
api_endpoint = ApiEndpoint(pattern, parent_pattern, self.drf_router)
api_endpoint = ApiEndpoint(pattern, ancestors_patterns, self.drf_router)
self.endpoints.append(api_endpoint)

def _is_drf_view(self, pattern):
Expand Down
4 changes: 2 additions & 2 deletions rest_framework_docs/api_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

class ApiEndpoint(object):

def __init__(self, pattern, parent_pattern=None, drf_router=None):
def __init__(self, pattern, ancestors_patterns=[], drf_router=None):
self.drf_router = drf_router
self.pattern = pattern
self.callback = pattern.callback
# self.name = pattern.name
self.docstring = self.__get_docstring__()
self.name_parent = simplify_regex(parent_pattern.regex.pattern).strip('/') if parent_pattern else None
self.name_parent = ''.join([simplify_regex(parent_pattern.regex.pattern).rstrip('/') for parent_pattern in ancestors_patterns]).lstrip('/') if ancestors_patterns else None
self.path = self.__get_path__(parent_pattern)
self.allowed_methods = self.__get_allowed_methods__()
# self.view_name = pattern.callback.__name__
Expand Down