Django

drf swagger 문서화

끈끈 2023. 5. 29. 22:55

 

https://drf-yasg.readthedocs.io/en/stable/readme.html

 

drf-yasg - Yet another Swagger generator — drf-yasg 1.20.1 documentation

Since the schema does not usually change during the lifetime of the django process, there is out of the box support for caching the schema view in-memory, with some sane defaults: caching is enabled by the cache_page decorator, using the default Django cac

drf-yasg.readthedocs.io

 

pip install drf-yasg

 

 

settings.py:

INSTALLED_APPS = [
    
    'django.contrib.staticfiles',
    'drf_yasg',
    
]

 

urls.py:

...
from django.urls import path,include, re_path # re_path 추가
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="Incheon Jumak", # 프로젝트 이름
        default_version='v1', # 프로젝트 버전
        description="Incheon Jumak test API 문서", # 해당 문서 설명
        terms_of_service="https://www.google.com/policies/terms/",
        contact=openapi.Contact(email="incheonjumak@gmail.com"), # 부가정보
        license=openapi.License(name="A2_YUNIBUS"), # 부가정보
    ),
    public=True,
    permission_classes=[permissions.AllowAny],
)

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'),
   ...
]

 

 

 

https://django-rest-swagger.readthedocs.io/en/latest/settings/

 

Settings - Django REST Swagger

Settings The configuration of Django REST Swagger is identical to Django REST Framework. Settings are configurable in settings.py by defining SWAGGER_SETTINGS. Example: settings.py SWAGGER_SETTINGS = { 'SECURITY_DEFINITIONS': { 'basic': { 'type': 'basic' }

django-rest-swagger.readthedocs.io

 

https://drf-yasg.readthedocs.io/en/stable/custom_spec.html

 

Custom schema generation — drf-yasg 1.20.1 documentation

for ViewSet, GenericViewSet, ModelViewSet, because each viewset corresponds to multiple paths, you have to decorate the action methods, i.e. list, create, retrieve, etc. Additionally, @actions defined on the viewset, like function based api views, can resp

drf-yasg.readthedocs.io

 

'Django' 카테고리의 다른 글

django signal pre_save  (2) 2023.06.15
drf filter __ 언더스코어  (4) 2023.06.14
Django admin 페이지 커스텀하기  (1) 2023.05.23
Django sqlite3 mysql로 변경하기  (11) 2023.05.09
DRF BooleanField  (2) 2023.04.25