Skip to content

Commit

Permalink
swagger 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
ashee022 committed Sep 12, 2023
1 parent df3a281 commit 7bdaa71
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 3 deletions.
12 changes: 10 additions & 2 deletions .idea/dbnavigator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions buzzing_admin/swagger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from drf_yasg.utils import swagger_auto_schema
from drf_yasg.inspectors import SwaggerAutoSchema
from drf_yasg import openapi

class BearerTokenAutoSchema(SwaggerAutoSchema):
def get_security_definitions(self, auto_schema_context):
security_definitions = super(BearerTokenAutoSchema, self).get_security_definitions(auto_schema_context)
security_definitions['Bearer'] = openapi.SecurityScheme(
type=openapi.TYPE_API_KEY,
in_=openapi.IN_HEADER,
name='Authorization',
description="JWT 토큰 키를 입력해주세요!"
)
return security_definitions

def admin_login_view_schema():
return {
'request_body': openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'social_email': openapi.Schema(type=openapi.TYPE_STRING, description='Admin email', example="[email protected]"),
'password': openapi.Schema(type=openapi.TYPE_STRING, description='Admin password', example="passwd1234"),
},
),
'responses': {
200: openapi.Response(description='Successful Login', schema=openapi.Schema(type=openapi.TYPE_OBJECT, properties={'AccessToken': openapi.Schema(type=openapi.TYPE_STRING, example="sampleAccessToken12345")})),
400: 'INVALID_DATA',
403: 'NO_PERMISSION',
401: 'INVALID_USER'
},
'operation_description': "Admin login view \n 관리자 아이디로 접속시, users.USER_ROLE이 ADMIN일시 토큰발급"
}


def admin_main_view_schema():
return {
'responses': {
200: openapi.Response(description='Get reported contents and banned users'),
},
'operation_description': "관리자 메인 페이지"
}

def unban_user_view_schema():
return {
'responses': {
200: "유저 정지 해제 완료.",
400: "밴 데이터가 없습니다."
},
'operation_description': "유저 정지 해제"
}

def report_detail_view_get_schema():
return {
'responses': {
200: openapi.Response(description='Get report detail'),
},
'operation_description': "리폿 상세뷰 가져오기"
}

def report_detail_view_post_schema():
return {
'request_body': openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'action': openapi.Schema(type=openapi.TYPE_STRING, description='Action to take (무고, 30일 정지, 블랙리스트)'),
'ban_reason': openapi.Schema(type=openapi.TYPE_STRING, description='밴 사유'),
'ban_reason_title': openapi.Schema(type=openapi.TYPE_STRING, description='밴 사유 제목'),
},
required=['action', 'ban_reason', 'ban_reason_title'],
example={
'action': '30일 정지',
'ban_reason': '비매너 행동으로 다수의 신고가 접수됨',
'ban_reason_title': '비매너 행동'
}
),
'responses': {
200: "신고 처리 완료.",
400: "유저가 이미 밴 상태입니다..",
},
'operation_description': "리폿 처리"
}

32 changes: 32 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,40 @@
#스케줄러
'django_crontab',
'buzzing_admin',

#swagger
'drf_yasg',
'rest_framework',
]

SWAGGER_SETTINGS = {
'DEFAULT_AUTO_SCHEMA_CLASS': 'buzzing_admin.swagger.BearerTokenAutoSchema',
'SECURITY_DEFINITIONS': {
'Bearer': {
'type': 'apiKey',
'name': 'Authorization',
'in': 'header'
}
},
'DEFAULT_SECURITY': [
{
'Bearer': []
}
],

'USE_SESSION_AUTH': False,

'DEFAULT_FIELD_INSPECTORS': [
'drf_yasg.inspectors.CamelCaseJSONFilter',
'drf_yasg.inspectors.InlineSerializerInspector',
'drf_yasg.inspectors.RelatedFieldInspector',
'drf_yasg.inspectors.ChoiceFieldInspector',
'drf_yasg.inspectors.FileFieldInspector',
'drf_yasg.inspectors.DictFieldInspector',
'drf_yasg.inspectors.SerializerMethodFieldInspector',
],
}


MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
Expand Down
19 changes: 18 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@
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 path,re_path
from getApi import views
from buzzing_admin import admin_views
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="API",
default_version='v1',
description="🚀 Realtime Congestion Based Location Recommendation Service - 복쟉복쟉 admin_Server의 API 명세서입니다.",
),
public=True,
permission_classes=(permissions.AllowAny,),
)

urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -26,6 +40,9 @@
path('auth/admin/main/', admin_views.AdminMainView.as_view()),
path('auth/admin/report/<int:report_id>/', admin_views.ReportDetailView.as_view()),
path('auth/admin/report/<int:user_id>/unBan/', admin_views.UnbanUserView.as_view(), name='unBan'),
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]


Expand Down
2 changes: 2 additions & 0 deletions install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ urllib3==1.26.15
uWSGI==2.0.21
xlwt==1.3.0
xmltodict==0.13.0
drf-yasg==1.21.7

0 comments on commit 7bdaa71

Please sign in to comment.