From 8bf990b5f6744f4a36f2b7e179b60803a67448b1 Mon Sep 17 00:00:00 2001 From: Derinhelm Date: Wed, 14 Apr 2021 00:13:00 +0300 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20Swagger=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://0.0.0.0:8000/swagger/ --- backend/backend/api.py | 2 +- backend/backend/settings.py | 3 ++- backend/backend/urls.py | 14 ++++++++++++++ backend/requirements.txt | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/backend/api.py b/backend/backend/api.py index 3239ffc..5e309aa 100644 --- a/backend/backend/api.py +++ b/backend/backend/api.py @@ -13,7 +13,7 @@ class ToDoListSerializer(serializers.HyperlinkedModelSerializer): class ToDoListViewSet(viewsets.ModelViewSet): queryset = ToDoList.objects.all() serializer_class = ToDoListSerializer - permission_classes = [permissions.IsAuthenticated] + #permission_classes = [permissions.IsAuthenticated] TODO раскомментировать и сделать авторизацию router = routers.DefaultRouter() diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 31df526..05515d2 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -26,7 +26,7 @@ SECRET_KEY = "django-insecure-toz+*lt(ejm!l*)92w2ciqoh^1kz#a(abbpcn54-dbw(nxoy&7 # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["0.0.0.0"] # Application definition @@ -40,6 +40,7 @@ INSTALLED_APPS = [ "django.contrib.messages", "django.contrib.staticfiles", "rest_framework", + "drf_yasg", ] MIDDLEWARE = [ 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..9ff2e56 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 From df54d92eccdbcd2843bb6aed9dae989314a4607e Mon Sep 17 00:00:00 2001 From: Derinhelm Date: Wed, 14 Apr 2021 13:13:06 +0300 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=D0=92=20Swagger=20UI=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20JWT-=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/backend/api.py | 2 +- backend/backend/settings.py | 15 +++++++++++++-- backend/requirements.txt | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/backend/backend/api.py b/backend/backend/api.py index 5e309aa..3239ffc 100644 --- a/backend/backend/api.py +++ b/backend/backend/api.py @@ -13,7 +13,7 @@ class ToDoListSerializer(serializers.HyperlinkedModelSerializer): class ToDoListViewSet(viewsets.ModelViewSet): queryset = ToDoList.objects.all() serializer_class = ToDoListSerializer - #permission_classes = [permissions.IsAuthenticated] TODO раскомментировать и сделать авторизацию + permission_classes = [permissions.IsAuthenticated] router = routers.DefaultRouter() diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 05515d2..54f089b 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -26,8 +26,9 @@ SECRET_KEY = "django-insecure-toz+*lt(ejm!l*)92w2ciqoh^1kz#a(abbpcn54-dbw(nxoy&7 # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["0.0.0.0"] - +ALLOWED_HOSTS = [] +if DEBUG: + ALLOWED_HOSTS = ["0.0.0.0"] # Application definition @@ -43,6 +44,16 @@ INSTALLED_APPS = [ "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/requirements.txt b/backend/requirements.txt index 9ff2e56..b4b923b 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -21,4 +21,4 @@ toml==0.10.2 urllib3==1.26.4 djangorestframework-simplejwt==4.6.0 psycopg2-binary>=2.8 -drf-yasg +drf-yasg>=1.20.0 From 88e19efc0b0e49718c514ab393109ecd04aaa0e5 Mon Sep 17 00:00:00 2001 From: Derinhelm Date: Wed, 14 Apr 2021 13:27:05 +0300 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=D0=97=D0=B0=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=81=D0=B8=D1=8F=20drf-yasg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index b4b923b..733426f 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -21,4 +21,4 @@ toml==0.10.2 urllib3==1.26.4 djangorestframework-simplejwt==4.6.0 psycopg2-binary>=2.8 -drf-yasg>=1.20.0 +drf-yasg==1.20.0