Skip to content

Commit a3c7ffb

Browse files
committed
Bugfix: an endpoint without a parent contaminated with its predecessor's parent.
1 parent 4cb10da commit a3c7ffb

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Diff for: rest_framework_docs/api_docs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def __init__(self, drf_router=None):
2424
def get_all_view_names(self, urlpatterns, parent_pattern=None):
2525
for pattern in urlpatterns:
2626
if isinstance(pattern, RegexURLResolver):
27-
parent_pattern = None if pattern._regex == "^" else pattern
28-
self.get_all_view_names(urlpatterns=pattern.url_patterns, parent_pattern=parent_pattern)
27+
new_parent_pattern = None if pattern._regex == "^" else pattern
28+
self.get_all_view_names(urlpatterns=pattern.url_patterns, parent_pattern=new_parent_pattern)
2929
elif isinstance(pattern, RegexURLPattern) and self._is_drf_view(pattern) and not self._is_format_endpoint(pattern):
3030
api_endpoint = ApiEndpoint(pattern, parent_pattern, self.drf_router)
3131
self.endpoints.append(api_endpoint)

Diff for: tests/tests.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def test_index_view_with_endpoints(self):
4949
# The view "OrganisationErroredView" (organisations/(?P<slug>[\w-]+)/errored/) should contain an error.
5050
self.assertEqual(str(response.context["endpoints"][9].errors), "'test_value'")
5151

52+
self.assertEqual(response.context["endpoints"][14].path, "/another-login/")
53+
5254
def test_index_search_with_endpoints(self):
5355
response = self.client.get("%s?search=reset-password" % reverse("drfdocs"))
5456

@@ -75,8 +77,8 @@ def test_model_viewset(self):
7577

7678
self.assertEqual(response.context["endpoints"][10].path, '/organisations/<slug>/')
7779
self.assertEqual(response.context['endpoints'][6].fields[2]['to_many_relation'], True)
78-
self.assertEqual(response.context["endpoints"][11].path, '/organisation-model-viewsets/')
79-
self.assertEqual(response.context["endpoints"][12].path, '/organisation-model-viewsets/<pk>/')
80+
self.assertEqual(response.context["endpoints"][11].path, '/router/organisation-model-viewsets/')
81+
self.assertEqual(response.context["endpoints"][12].path, '/router/organisation-model-viewsets/<pk>/')
8082
self.assertEqual(response.context["endpoints"][11].allowed_methods, ['GET', 'POST', 'OPTIONS'])
8183
self.assertEqual(response.context["endpoints"][12].allowed_methods, ['GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'])
8284
self.assertEqual(response.context["endpoints"][13].allowed_methods, ['POST', 'OPTIONS'])

Diff for: tests/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# API
3737
url(r'^accounts/', view=include(accounts_urls, namespace='accounts')),
3838
url(r'^organisations/', view=include(organisations_urls, namespace='organisations')),
39-
url(r'^', include(router.urls)),
39+
url(r'^router/', include(router.urls)),
4040

4141
# Endpoints without parents/namespaces
4242
url(r'^another-login/$', views.LoginView.as_view(), name="login"),

0 commit comments

Comments
 (0)