From 637c4fbc107af20949d92083ecfac1529ea48e2c Mon Sep 17 00:00:00 2001 From: Bram Meir Date: Sat, 2 Mar 2024 18:24:42 +0100 Subject: [PATCH 1/2] chore: init swagger --- backend/ypovoli/settings.py | 21 +++++++++++++++++++++ backend/ypovoli/urls.py | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/backend/ypovoli/settings.py b/backend/ypovoli/settings.py index c912fa45..7552d92e 100644 --- a/backend/ypovoli/settings.py +++ b/backend/ypovoli/settings.py @@ -36,6 +36,7 @@ "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", + 'django.contrib.staticfiles', # Third party "rest_framework_swagger", # Swagger @@ -109,3 +110,23 @@ USE_I18N = True USE_L10N = False USE_TZ = True + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ +STATIC_URL = 'static/' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] diff --git a/backend/ypovoli/urls.py b/backend/ypovoli/urls.py index 6f4771a1..f4cf1d40 100644 --- a/backend/ypovoli/urls.py +++ b/backend/ypovoli/urls.py @@ -15,6 +15,18 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.urls import path, include +from rest_framework import permissions +from drf_yasg.views import get_schema_view +from drf_yasg import openapi + +schema_view = get_schema_view( + openapi.Info( + title="YpoVoli API", + default_version='v1',), + public=True, + permission_classes=(permissions.AllowAny,), +) + urlpatterns = [ # Base API endpoints. @@ -22,4 +34,9 @@ # Authentication endpoints. path("auth/", include("authentication.urls")), path("notifications/", include("notifications.urls")), + # Swagger documentation. + path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), + name='schema-swagger-ui'), + path('swagger/', schema_view.without_ui(cache_timeout=0), + name='schema-json'), ] From c27bdba2538f8e8a2e801e7d22d771e9153d079b Mon Sep 17 00:00:00 2001 From: Bram Meir Date: Sat, 2 Mar 2024 18:51:59 +0100 Subject: [PATCH 2/2] fix: typo --- backend/ypovoli/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/ypovoli/urls.py b/backend/ypovoli/urls.py index f4cf1d40..cb541b25 100644 --- a/backend/ypovoli/urls.py +++ b/backend/ypovoli/urls.py @@ -21,7 +21,7 @@ schema_view = get_schema_view( openapi.Info( - title="YpoVoli API", + title="Ypovoli API", default_version='v1',), public=True, permission_classes=(permissions.AllowAny,),