Skip to content

Commit d95c978

Browse files
authored
Fix/openapi drf spectacular v2 (#420)
* Replace DRF built-in OpenAPI with drf-spectacular Adds drf-spectacular for OpenAPI schema generation and pins cachetools and pytz explicitly in Pipfile to prevent transitive dep drops on clean Docker builds (root cause of the prod outage in #413). * disable drf-spectacular errors and warnings for prod * Pin pytz, remove cachetools, regenerate Pipfile.lock from scratch pytz is a hard runtime dep of pandas but was silently dropped by pipenv's resolver — same class of bug that caused the #413 outage. cachetools removed since google-auth 2.49.1 (upgraded transitively via firebase-admin 7.1.0→7.3.0) no longer imports it.
1 parent 738448d commit d95c978

6 files changed

Lines changed: 1223 additions & 1056 deletions

File tree

backend/Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pre-commit = "*"
4949
alt-profanity-check = "*"
5050
inflection = "*"
5151
firebase-admin = "*"
52+
drf-spectacular = "*"
53+
pytz = "*"
5254

5355
[requires]
5456
python_version = "3.11"

backend/Pipfile.lock

Lines changed: 1203 additions & 1024 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/pennmobile/settings/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"analytics.apps.AnalyticsConfig",
5353
"wrapped.apps.WrappedConfig",
5454
"django_filters",
55+
"drf_spectacular",
5556
"debug_toolbar",
5657
"gsr_booking",
5758
"portal",
@@ -156,6 +157,13 @@
156157
"rest_framework.authentication.BasicAuthentication",
157158
"accounts.authentication.PlatformAuthentication",
158159
],
160+
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
161+
}
162+
163+
SPECTACULAR_SETTINGS = {
164+
"TITLE": "Penn Mobile Backend Documentation",
165+
"VERSION": "1.0.0",
166+
"SERVE_PUBLIC": True,
159167
}
160168

161169
# Redis for Celery & Caching

backend/pennmobile/settings/production.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sentry_sdk.types import Event, Hint
77

88
from pennmobile.settings.base import * # noqa: F401, F403
9-
from pennmobile.settings.base import DOMAINS, REDIS_URL
9+
from pennmobile.settings.base import DOMAINS, REDIS_URL, SPECTACULAR_SETTINGS
1010

1111

1212
DEBUG = False
@@ -50,3 +50,8 @@ def before_send(event: Event, hint: Hint | None) -> Event | None:
5050
"OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"},
5151
}
5252
}
53+
54+
SPECTACULAR_SETTINGS = {
55+
**SPECTACULAR_SETTINGS,
56+
"DISABLE_ERRORS_AND_WARNINGS": True,
57+
}

backend/pennmobile/templates/redoc.html

Lines changed: 0 additions & 21 deletions
This file was deleted.

backend/pennmobile/urls.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from django.contrib import admin
33
from django.http import JsonResponse
44
from django.urls import include, path
5-
from django.views.generic import TemplateView
6-
from rest_framework.schemas import get_schema_view
5+
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
76

87

98
urlpatterns = [
@@ -13,18 +12,13 @@
1312
path("accounts/", include("accounts.urls", namespace="accounts")),
1413
path("user/", include("user.urls")),
1514
path("laundry/", include("laundry.urls")),
16-
path(
17-
"openapi/",
18-
get_schema_view(title="Penn Mobile Backend Documentation", public=True),
19-
name="openapi-schema",
20-
),
15+
path("openapi/", SpectacularAPIView.as_view(), name="openapi-schema"),
2116
path(
2217
"documentation/",
23-
TemplateView.as_view(
24-
template_name="redoc.html", extra_context={"schema_url": "openapi-schema"}
25-
),
18+
SpectacularSwaggerView.as_view(url_name="openapi-schema"),
2619
name="documentation",
2720
),
21+
path("redoc/", SpectacularRedocView.as_view(url_name="openapi-schema"), name="redoc"),
2822
path("dining/", include("dining.urls")),
2923
path("penndata/", include("penndata.urls")),
3024
path("sublet/", include("sublet.urls")),

0 commit comments

Comments
 (0)