post-thumb

Documentation Of Django API

In this tutorial we will lean how to make documenation of Djagno API.

1.Swagger Documentation Of Django  REST API

pip install  drf-yasg
#settings.py
INSTALLED_APPS = [
   ...
   'django.contrib.staticfiles',  # required for serving swagger ui's css/js files
   'drf_yasg',
   ...
]

SWAGGER_SETTINGS = {
    "SECURITY_DEFINITIONS": {
        "Auth Token eg [ BEARER (JWT) ]": {
            "type": "apiKey",
            "name": "Authorization",
            "in": "header"
        }
    }
}
#urls.py

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 DOCUMENTATION",
        default_version='v1',
        description="All The Necessary API For Income And Expenses",
        terms_of_service="https://www.ourapp.com/policies/terms/",
        contact=openapi.Contact(email="amritpanta77@gmail.com"),
        license=openapi.License(name="Test License"),
    ),
    public=True,
    permission_classes=[permissions.AllowAny],
)
urlpatterns = [
    path('admin/', admin.site.urls),
    # for documentation
    path('', 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'),
]

 

#views.py
class VerifyEmailAPIView(APIView):
    serializer_class = EmailVerifiactionSerializer
    token_param_config = openapi.Parameter(
        'token', in_=openapi.IN_QUERY, description='Description', type=openapi.TYPE_STRING)

    @swagger_auto_schema(manual_parameters=[token_param_config])
    def get(self, request):

 

for more info docs