From 8bf990b5f6744f4a36f2b7e179b60803a67448b1 Mon Sep 17 00:00:00 2001 From: Derinhelm Date: Wed, 14 Apr 2021 00:13:00 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=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