diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 31df526..54f089b 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -27,7 +27,8 @@ SECRET_KEY = "django-insecure-toz+*lt(ejm!l*)92w2ciqoh^1kz#a(abbpcn54-dbw(nxoy&7 DEBUG = True ALLOWED_HOSTS = [] - +if DEBUG: + ALLOWED_HOSTS = ["0.0.0.0"] # Application definition @@ -40,8 +41,19 @@ INSTALLED_APPS = [ "django.contrib.messages", "django.contrib.staticfiles", "rest_framework", + "drf_yasg", ] +SWAGGER_SETTINGS = { + 'SECURITY_DEFINITIONS': { + 'Bearer': { + 'type': 'apiKey', + 'name': 'Authorization', + 'in': 'header' + } + } +} + MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", diff --git a/backend/backend/urls.py b/backend/backend/urls.py index 2527f6e..d123db5 100644 --- a/backend/backend/urls.py +++ b/backend/backend/urls.py @@ -6,8 +6,21 @@ from rest_framework_simplejwt.views import ( TokenRefreshView, ) +from rest_framework import permissions +from drf_yasg.views import get_schema_view +from drf_yasg import openapi + from .api import router +schema_view = get_schema_view( + openapi.Info( + title="ToDo List", + default_version='v1', + description="Swagger Interface for ToDo List", + ), + public=True, + permission_classes=(permissions.AllowAny,), +) urlpatterns = [ path("admin/", admin.site.urls), @@ -15,4 +28,5 @@ urlpatterns = [ path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"), path("api/", include(router.urls)), path("api-auth/", include("rest_framework.urls", namespace="rest_framework")), + path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), ] diff --git a/backend/requirements.txt b/backend/requirements.txt index 2232e5a..733426f 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -21,3 +21,4 @@ toml==0.10.2 urllib3==1.26.4 djangorestframework-simplejwt==4.6.0 psycopg2-binary>=2.8 +drf-yasg==1.20.0