[ADD] HORILLA_API: Add swagger
This commit is contained in:
@@ -1,12 +1,54 @@
|
||||
from django.contrib.auth import authenticate
|
||||
from drf_yasg import openapi
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
from ...api_serializers.auth.serializers import GetEmployeeSerializer
|
||||
from horilla_api.docs import document_api
|
||||
|
||||
from ...api_serializers.auth.serializers import (
|
||||
GetEmployeeSerializer,
|
||||
LoginRequestSerializer,
|
||||
)
|
||||
|
||||
|
||||
class LoginAPIView(APIView):
|
||||
@document_api(
|
||||
operation_description="Authenticate user and return JWT access token with employee info",
|
||||
request_body=LoginRequestSerializer,
|
||||
responses={
|
||||
200: openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
"employee": openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
"id": openapi.Schema(type=openapi.TYPE_INTEGER),
|
||||
"full_name": openapi.Schema(type=openapi.TYPE_STRING),
|
||||
"employee_profile": openapi.Schema(
|
||||
type=openapi.TYPE_STRING,
|
||||
description="Profile image URL",
|
||||
),
|
||||
},
|
||||
),
|
||||
"access": openapi.Schema(
|
||||
type=openapi.TYPE_STRING, description="JWT access token"
|
||||
),
|
||||
"face_detection": openapi.Schema(type=openapi.TYPE_BOOLEAN),
|
||||
"face_detection_image": openapi.Schema(
|
||||
type=openapi.TYPE_STRING,
|
||||
description="Face detection image URL",
|
||||
nullable=True,
|
||||
),
|
||||
"geo_fencing": openapi.Schema(type=openapi.TYPE_BOOLEAN),
|
||||
"company_id": openapi.Schema(
|
||||
type=openapi.TYPE_INTEGER, nullable=True
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
tags=["auth"],
|
||||
)
|
||||
def post(self, request):
|
||||
if "username" and "password" in request.data.keys():
|
||||
username = request.data.get("username")
|
||||
|
||||
29
horilla_api/api_views/base/example_view.py
Normal file
29
horilla_api/api_views/base/example_view.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
Example API view with documentation
|
||||
"""
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from horilla_api.docs import document_api
|
||||
|
||||
class ExampleDocumentedView(APIView):
|
||||
"""
|
||||
Example view demonstrating API documentation
|
||||
"""
|
||||
|
||||
@document_api(
|
||||
operation_description="Get API documentation example",
|
||||
responses={
|
||||
200: "Example response with documentation",
|
||||
404: "Not found error"
|
||||
},
|
||||
tags=['Documentation Example']
|
||||
)
|
||||
def get(self, request):
|
||||
"""
|
||||
Example GET method with documentation
|
||||
"""
|
||||
return Response(
|
||||
{"message": "API documentation is working correctly"},
|
||||
status=status.HTTP_200_OK
|
||||
)
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import Any
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
@@ -163,7 +165,7 @@ class DepartmentView(APIView):
|
||||
|
||||
departments = Department.objects.all()
|
||||
paginator = PageNumberPagination()
|
||||
page = paginator.paginate_queryset(departments, request)
|
||||
page: list[Any] | None = paginator.paginate_queryset(departments, request)
|
||||
serializer = self.serializer_class(page, many=True)
|
||||
return paginator.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user