Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: swagger 추가 #9

Merged
merged 4 commits into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -3,8 +3,11 @@ Django==4.2.8
django-debug-toolbar==4.2.0
django-environ==0.11.2
djangorestframework==3.14.0
psycopg2-binary==2.9.9
python-environ==0.4.54
drf-yasg==1.21.7
inflection==0.5.1
packaging==23.2
pytz==2023.3.post1
PyYAML==6.0.1
sqlparse==0.4.4
typing_extensions==4.9.0
uritemplate==4.1.1
6 changes: 4 additions & 2 deletions src/settings.py
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@
"""

from pathlib import Path
import os
import environ
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

env = environ.Env(DEBUG=(bool, True))

@@ -44,6 +44,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'drf_yasg',
]

MIDDLEWARE = [
30 changes: 29 additions & 1 deletion src/urls.py
Original file line number Diff line number Diff line change
@@ -15,8 +15,36 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path, re_path
from django.conf import settings
from rest_framework import routers, permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

router = routers.DefaultRouter()

schema_view = get_schema_view(
openapi.Info(
title="ft_transcendence API",
default_version="v1.0.0",
description="Test description",
terms_of_service="https://www.google.com/policies/terms/",
),
public=True,
permission_classes=[permissions.AllowAny, ],
)

urlpatterns = [
path('admin/', admin.site.urls),
]

# DEBUG 모드일 경우, ui 없이 swagger view를 사용할 수 있도록 설정
if settings.DEBUG:
urlpatterns += [
re_path(r'^swagger(?P<format>\.json|\.yaml)$',
schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^swagger/$', schema_view.with_ui('swagger',
cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^redoc/$', schema_view.with_ui('redoc',
cache_timeout=0), name='schema-redoc'),
]