Skip to content

Commit 64d52ec

Browse files
authored
Stop using drf-spectacular (#542)
- Use Redoc instead of swagger - Don't rely on CDN - Fix docs for bulk_search API Signed-off-by: Shivam Sandbhor <[email protected]>
1 parent 2519f65 commit 64d52ec

23 files changed

+1002
-21
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ aiohttp>=3.7.4.post0
55
djangorestframework>=3.12.4
66
django-filter>=2.4.0
77
django-widget-tweaks>=1.4.8
8-
drf-spectacular>=0.17.1
98
packageurl-python>=0.9.4
109
binaryornot>=0.4.4
1110
GitPython>=3.1.17

vulnerabilities/api.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from urllib.parse import unquote
2525

2626
from django_filters import rest_framework as filters
27-
from drf_spectacular.utils import extend_schema, inline_serializer
2827
from packageurl import PackageURL
2928

3029
from rest_framework import serializers, viewsets
@@ -35,10 +34,6 @@
3534
from vulnerabilities.models import VulnerabilityReference
3635
from vulnerabilities.models import VulnerabilitySeverity
3736

38-
# This serializer is used for the bulk apis, to prevent wrong auto documentation
39-
# TODO: Fix the swagger documentation for bulk apis
40-
placeholder_serializer = inline_serializer(name="Placeholder", fields={})
41-
4237

4338
class VulnerabilitySeveritySerializer(serializers.ModelSerializer):
4439
class Meta:
@@ -135,7 +130,6 @@ class PackageViewSet(viewsets.ReadOnlyModelViewSet):
135130
filterset_class = PackageFilterSet
136131

137132
# TODO: Fix the swagger documentation for this endpoint
138-
@extend_schema(request=placeholder_serializer, responses=placeholder_serializer)
139133
@action(detail=False, methods=["post"])
140134
def bulk_search(self, request):
141135
"""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>VulnerableCode API</title>
6+
<meta charset="utf-8"/>
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link href="{% static 'api_doc/font.css' %}" rel="stylesheet">
9+
10+
<style>
11+
body {
12+
margin: 0;
13+
padding: 0;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<redoc spec-url="{% static 'api_doc/api_schema.yaml' %}"></redoc>
19+
<script src="{% static 'api_doc/redoc.standalone.js' %}"> </script>
20+
</body>
21+
</html>

vulnerabilities/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a class="navbar-item" href="{% url 'home' %}">
1515
Home
1616
</a>
17-
<a class="navbar-item" href="{% url 'swagger-ui' %}">
17+
<a class="navbar-item" href="{% url 'redoc' %}">
1818
API Docs
1919
</a>
2020
{% if enable_curation %}

vulnerabilities/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from django.core.paginator import Paginator
2626
from django.db.models import Count
2727
from django.http import HttpResponse
28+
from django.http.response import HttpResponseNotAllowed
2829
from django.shortcuts import render, redirect
2930
from django.urls import reverse
3031
from django.views import View
@@ -248,3 +249,9 @@ def form_valid(self, form):
248249

249250
def get_success_url(self):
250251
return reverse("vulnerability_view", kwargs={"pk": self.kwargs["vid"]})
252+
253+
254+
def schema_view(request):
255+
if request.method != "GET":
256+
return HttpResponseNotAllowed()
257+
return render(request, "api_doc.html")

vulnerablecode/settings.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
SECRET_KEY = env.str("SECRET_KEY")
1717

1818
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[".localhost", "127.0.0.1", "[::1]"])
19+
DEBUG = True
1920

2021
# Application definition
2122

@@ -30,7 +31,6 @@
3031
"rest_framework",
3132
"django_filters",
3233
"widget_tweaks",
33-
"drf_spectacular",
3434
]
3535

3636
MIDDLEWARE = [
@@ -122,8 +122,7 @@
122122
# Static files (CSS, JavaScript, Images)
123123

124124
STATIC_URL = "/static/"
125-
126-
STATIC_ROOT = "/var/vulnerablecode/static"
125+
STATIC_ROOT = "./"
127126

128127
STATICFILES_DIRS = [
129128
str(PROJECT_DIR.joinpath("static")),
@@ -134,14 +133,7 @@
134133
"DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",),
135134
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
136135
"PAGE_SIZE": 100,
137-
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
138-
}
139-
140-
SPECTACULAR_SETTINGS = {
141-
"SERVE_INCLUDE_SCHEMA": False,
142-
"TITLE": "VulnerableCode API",
143136
}
144-
# TODO: Specify the license for the API here.
145137

146138
# Set this to true to enable community curation, ie users will be able to edit data
147139
ENABLE_CURATION = False
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*!
2+
* ReDoc - OpenAPI/Swagger-generated API Reference Documentation
3+
* -------------------------------------------------------------
4+
* Version: "2.0.0-rc.56"
5+
* Repo: https://github.com/Redocly/redoc
6+
*/
7+
8+
/*!
9+
* lunr.Builder
10+
* Copyright (C) 2020 Oliver Nightingale
11+
*/
12+
13+
/*!
14+
* lunr.Index
15+
* Copyright (C) 2020 Oliver Nightingale
16+
*/
17+
18+
/*!
19+
* lunr.Pipeline
20+
* Copyright (C) 2020 Oliver Nightingale
21+
*/
22+
23+
/*!
24+
* lunr.Set
25+
* Copyright (C) 2020 Oliver Nightingale
26+
*/
27+
28+
/*!
29+
* lunr.TokenSet
30+
* Copyright (C) 2020 Oliver Nightingale
31+
*/
32+
33+
/*!
34+
* lunr.Vector
35+
* Copyright (C) 2020 Oliver Nightingale
36+
*/
37+
38+
/*!
39+
* lunr.stemmer
40+
* Copyright (C) 2020 Oliver Nightingale
41+
* Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt
42+
*/
43+
44+
/*!
45+
* lunr.stopWordFilter
46+
* Copyright (C) 2020 Oliver Nightingale
47+
*/
48+
49+
/*!
50+
* lunr.tokenizer
51+
* Copyright (C) 2020 Oliver Nightingale
52+
*/
53+
54+
/*!
55+
* lunr.trimmer
56+
* Copyright (C) 2020 Oliver Nightingale
57+
*/
58+
59+
/*!
60+
* lunr.utils
61+
* Copyright (C) 2020 Oliver Nightingale
62+
*/
63+
64+
/**
65+
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.9
66+
* Copyright (C) 2020 Oliver Nightingale
67+
* @license MIT
68+
*/

vulnerablecode/static/api_doc/9bcbfb5fe4bb244b68d4.worker.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)