Skip to content

Commit

Permalink
chore(api): remove OpenAPI/Swagger integration
Browse files Browse the repository at this point in the history
The `django-rest-framework`'s built-in support for OpenAPI schema
generation has been deprecated (encode/django-rest-framework#8773).
`drf-spectacular` is the recommended alternative, but CourtListener's
schema has always been experimental. Moreover the current integration
is crashing and has other bugs that prevent its effective use.
Outright removal, rather than replacement is the best way forward.

Fixes: freelawproject#3653, freelawproject#1616
  • Loading branch information
cweider committed Feb 13, 2024
1 parent e2358a9 commit 1875b99
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 177 deletions.
5 changes: 1 addition & 4 deletions cl/api/templates/rest-docs-vlatest.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2 id="api-overview">Getting Started &amp; Overview</h2>

<pre class="scrollable">curl -X OPTIONS "{% get_full_host %}{% url "api-root" version="v3" %}"</pre>

<p>An <code>OPTIONS</code> request is typically the best way to understand the API, however as of v3.1 we also offer an experimental <a href="{% url "swagger_schema" %}">swagger/OpenAPI interface</a>. These endpoints can be used with <a href="http://www.django-rest-framework.org/topics/api-clients/">a variety of bindings</a> to incorporate the API into your code.
<p>An <code>OPTIONS</code> request is typically the best way to understand the API.
</p>


Expand Down Expand Up @@ -486,9 +486,6 @@ <h2 id="endpoints">Endpoints</h2>
<a href="{% url "api-root" version="v3" %}"
target="_blank"
class="btn btn-lg btn-primary">Show All Endpoints</a>
<a href="{% url "swagger_schema" %}"
target="_blank"
class="btn btn-lg btn-primary">Show Swagger Schema</a>
</p>
<h3 id="docket-endpoint">{% url "docket-list" version="v3" %}</h3>
<p><code>Docket</code> objects link <code>Opinion Cluster</code>, <code>Audio</code>, and <code>Docket Entry</code> objects together, following the conventional definition of a docket. As with all other endpoints, you can look up the field descriptions, filtering options, ordering options, and rendering options by making an <code>OPTIONS</code> request.
Expand Down
4 changes: 0 additions & 4 deletions cl/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ async def test_api_index(self) -> None:
r = await self.async_client.get(reverse("api_index"))
self.assertEqual(r.status_code, 200)

async def test_swagger_interface(self) -> None:
r = await self.async_client.get(reverse("swagger_schema"))
self.assertEqual(r.status_code, 200)

async def test_options_request(self) -> None:
r = await self.async_client.options(reverse("court_index"))
self.assertEqual(r.status_code, 200)
Expand Down
15 changes: 1 addition & 14 deletions cl/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.urls import include, path, re_path
from django.views.generic import RedirectView
from rest_framework.renderers import JSONOpenAPIRenderer
from rest_framework.routers import DefaultRouter
from rest_framework.schemas import get_schema_view

from cl.alerts import api_views as alert_views
from cl.api import views
Expand Down Expand Up @@ -148,7 +146,7 @@
API_TITLE = "CourtListener Legal Data API"


urlpatterns_base = [
urlpatterns = [
path(
"api-auth/",
include("rest_framework.urls", namespace="rest_framework"),
Expand Down Expand Up @@ -230,14 +228,3 @@
RedirectView.as_view(pattern_name="replication_docs", permanent=True),
),
]

schema_view = get_schema_view(
title=API_TITLE,
url="https://www.courtlistener.com/api/rest/v3/",
renderer_classes=[JSONOpenAPIRenderer],
patterns=urlpatterns_base,
)

urlpatterns = urlpatterns_base + [
path("api/swagger/", schema_view, name="swagger_schema"),
]
154 changes: 1 addition & 153 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ natsort = "^8.4.0"
ndg-httpsclient = "^0.5.1"
networkx = "^3.2.1"
nose = "*"
openapi-codec = "^1.3.1"
pandas = "^2.1.4"
pillow = "*"
pycparser = "^2.21"
Expand Down Expand Up @@ -111,7 +110,6 @@ daphne = "^4.0.0"
psycopg = {extras = ["binary"], version = "^3.1.17"}
httpx = {extras = ["http2"], version = "^0.26.0"}
django-model-utils = "^4.3.1"
inflection = "^0.5.1" # necessary for DRF schema generation - remove after drf-spectacular
juriscraper = "*"
django-permissions-policy = "^4.19.0"

Expand Down

0 comments on commit 1875b99

Please sign in to comment.