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

Bugfix: an endpoint without a parent contaminated with its predecessor's parent. #126

Open
wants to merge 4 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
4 changes: 2 additions & 2 deletions rest_framework_docs/api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def __init__(self, drf_router=None):
def get_all_view_names(self, urlpatterns, parent_pattern=None):
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)
new_parent_pattern = None if pattern._regex == "^" else pattern
self.get_all_view_names(urlpatterns=pattern.url_patterns, parent_pattern=new_parent_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.drf_router)
self.endpoints.append(api_endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var LiveAPIEndpoints = React.createClass({
// Now Make the Request
APIRequest(request.selectedMethod, request.endpoint.path)
.set(headers)
.accept("json")
.send(data)
.end(function (err, res) {
self.setState({
Expand Down
12 changes: 6 additions & 6 deletions rest_framework_docs/static/rest_framework_docs/js/dist.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion rest_framework_docs/templates/rest_framework_docs/home.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "rest_framework_docs/docs.html" %}
{% load drfdocs_filters %}

{% block apps_menu %}
{% regroup endpoints by name_parent as endpoints_grouped %}
Expand Down Expand Up @@ -56,7 +57,7 @@ <h4 class="panel-title title">
<div id="{{ endpoint.path|slugify }}" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
{% if endpoint.docstring %}
<p class="lead">{{ endpoint.docstring }}</p>
<p class="lead">{{ endpoint.docstring|markdown }}</p>
{% endif %}

{% if endpoint.errors %}
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions rest_framework_docs/templatetags/drfdocs_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django import template
from django.template.defaultfilters import stringfilter
from rest_framework.utils.formatting import markup_description


register = template.Library()


@register.filter(name='markdown')
@stringfilter
def markdown(value):
return markup_description(value)
6 changes: 4 additions & 2 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def test_index_view_with_endpoints(self):
# The view "OrganisationErroredView" (organisations/(?P<slug>[\w-]+)/errored/) should contain an error.
self.assertEqual(str(response.context["endpoints"][9].errors), "'test_value'")

self.assertEqual(response.context["endpoints"][14].path, "/another-login/")

def test_index_search_with_endpoints(self):
response = self.client.get("%s?search=reset-password" % reverse("drfdocs"))

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

self.assertEqual(response.context["endpoints"][10].path, '/organisations/<slug>/')
self.assertEqual(response.context['endpoints'][6].fields[2]['to_many_relation'], True)
self.assertEqual(response.context["endpoints"][11].path, '/organisation-model-viewsets/')
self.assertEqual(response.context["endpoints"][12].path, '/organisation-model-viewsets/<pk>/')
self.assertEqual(response.context["endpoints"][11].path, '/router/organisation-model-viewsets/')
self.assertEqual(response.context["endpoints"][12].path, '/router/organisation-model-viewsets/<pk>/')
self.assertEqual(response.context["endpoints"][11].allowed_methods, ['GET', 'POST', 'OPTIONS'])
self.assertEqual(response.context["endpoints"][12].allowed_methods, ['GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'])
self.assertEqual(response.context["endpoints"][13].allowed_methods, ['POST', 'OPTIONS'])
Expand Down
2 changes: 1 addition & 1 deletion tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# API
url(r'^accounts/', view=include(accounts_urls, namespace='accounts')),
url(r'^organisations/', view=include(organisations_urls, namespace='organisations')),
url(r'^', include(router.urls)),
url(r'^router/', include(router.urls)),

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