Skip to content

Commit 8ff1900

Browse files
committed
Corrects copy pasta, fixes error made by copilot ;), adds a templates/swagger-ui.html, and adds to requirements.txt
1 parent b0f0f3b commit 8ff1900

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

drf_endpoint_examples/urls.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
ReviewViewSet,
3131
)
3232

33-
app_name = "drf-endpoint-examples"
33+
display_name = "DRF Endpoint Examples"
3434

3535

3636
router = routers.DefaultRouter()
@@ -40,22 +40,18 @@
4040
router.register(r"addresses", AddressViewSet)
4141
router.register(r"reviews", ReviewViewSet)
4242

43-
schema_url_patterns = [path(f"{app_name}/api/", include(router.urls))]
43+
schema_url_patterns = [path(f"api/", include(router.urls))]
4444

4545
urlpatterns = [
4646
path("admin/", admin.site.urls),
4747
path("api-auth/", include("rest_framework.urls")),
4848
path("api/", include(router.urls)),
4949
path(
50-
"openapi",
50+
"openapi/",
5151
staff_member_required(
5252
get_schema_view(
53-
title="Data Dictionary",
54-
description=(
55-
"Swagger API Documentation for Data Dictionary. See the "
56-
"[Data Dictionary Readme](/data-dictionary/readme) for more "
57-
"information."
58-
),
53+
title=display_name,
54+
description=f"Swagger API Documentation for {display_name}.",
5955
version="1.0.0",
6056
patterns=schema_url_patterns,
6157
generator_class=AuthSchemaGenerator,
@@ -67,11 +63,11 @@
6763
"swagger-ui/",
6864
staff_member_required(
6965
TemplateView.as_view(
70-
template_name="wrds/swagger-ui.html",
66+
template_name="swagger-ui.html",
7167
extra_context={
72-
"schema_url": "data-dictionary:openapi-schema",
73-
"api_name": "Data Dictionary",
74-
"api_swagger_url": "data-dictionary:swagger-ui",
68+
"schema_url": f"openapi-schema",
69+
"api_name": display_name,
70+
"api_swagger_url": f"swagger-ui",
7571
},
7672
)
7773
),

endpoints/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ class Meta:
2626
class ReviewSerializer(serializers.HyperlinkedModelSerializer):
2727
class Meta:
2828
model = Review
29-
fields = ['customer', 'product', 'rating', 'description']
29+
fields = ['customer', 'product', 'rating', 'review']

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ djangorestframework~=3.14.0
33
django-filter~=23.3
44
drf-api-logger~=1.1.14
55
Markdown~=3.5
6+
PyYAML~=6.0.1
7+
uritemplate~=4.1.1

templates/swagger-ui.html

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{% load static %}
2+
3+
{% block extra_head_bottom %}
4+
<link rel="stylesheet" type="text/css" href="//unpkg.com/swagger-ui-dist@3/swagger-ui.css"/>
5+
{% endblock extra_head_bottom %}
6+
7+
8+
{% block content %}
9+
<div id="swagger-ui"></div>
10+
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
11+
<script>
12+
const ui = SwaggerUIBundle({
13+
url: "{% url schema_url %}",
14+
dom_id: '#swagger-ui',
15+
presets: [
16+
SwaggerUIBundle.presets.apis,
17+
SwaggerUIBundle.SwaggerUIStandalonePreset
18+
],
19+
layout: "BaseLayout",
20+
defaultModelsExpandDepth: 3,
21+
defaultModelExpandDepth: 3,
22+
defaultModelRendering: "model",
23+
requestInterceptor: (request) => {
24+
request.headers['X-CSRFToken'] = "{{ csrf_token }}"
25+
return request;
26+
}
27+
})
28+
</script>
29+
</body>
30+
</html>
31+
{% endblock content %}

0 commit comments

Comments
 (0)