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

BITMAKER-2934 Improve estela generated OpenAPI documentation #171

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
53 changes: 49 additions & 4 deletions estela-api/api/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def retry_send_verification_email(self, user, request):
send_verification_email(user, request)

@swagger_auto_schema(
methods=["POST"], responses={status.HTTP_200_OK: TokenSerializer()}
methods=["POST"],
responses={status.HTTP_200_OK: TokenSerializer()},
tags=["auth"],
)
@action(methods=["POST"], detail=False)
def login(self, request, *args, **kwargs):
Expand All @@ -70,7 +72,9 @@ def login(self, request, *args, **kwargs):
return Response(TokenSerializer(token).data)

@swagger_auto_schema(
methods=["POST"], responses={status.HTTP_200_OK: TokenSerializer()}
methods=["POST"],
responses={status.HTTP_200_OK: TokenSerializer()},
tags=["auth"],
)
@action(methods=["POST"], detail=False, serializer_class=UserSerializer)
def register(self, request, *args, **kwargs):
Expand All @@ -93,6 +97,9 @@ def register(self, request, *args, **kwargs):
token, _ = Token.objects.get_or_create(user=user)
return Response(TokenSerializer(token).data)

@swagger_auto_schema(
tags=["auth"],
)
@action(methods=["GET"], detail=False)
def activate(self, request, *args, **kwargs):
token = request.query_params.get("token", "")
Expand Down Expand Up @@ -149,6 +156,7 @@ def get_queryset(self):

@swagger_auto_schema(
responses={status.HTTP_200_OK: UserProfileSerializer()},
tags=["auth"],
)
def retrieve(self, request, *args, **kwargs):
user: User = request.user
Expand All @@ -172,6 +180,7 @@ def retrieve(self, request, *args, **kwargs):

@swagger_auto_schema(
responses={status.HTTP_200_OK: UserProfileSerializer()},
tags=["auth"],
)
def update(self, request, *args, **kwargs):
username = kwargs.get("username", "")
Expand All @@ -196,11 +205,41 @@ def update(self, request, *args, **kwargs):
serializer.save()
return Response(data=serializer.data, status=status.HTTP_200_OK)

@swagger_auto_schema(
tags=["auth"],
)
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_201_CREATED: UserProfileSerializer()},
tags=["auth"],
)
def create(self, request, *args, **kwargs):
return super().create(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: UserProfileSerializer()},
tags=["auth"],
)
def partial_update(self, request, *args, **kwargs):
return super().partial_update(request, *args, **kwargs)

@swagger_auto_schema(
responses={
status.HTTP_204_NO_CONTENT: openapi.Response("No Content"),
},
tags=["auth"],
)
def destroy(self, request, *args, **kwargs):
return super().destroy(request, *args, **kwargs)


class ChangePasswordViewSet(viewsets.GenericViewSet):
@swagger_auto_schema(
request_body=ChangePasswordSerializer,
responses={status.HTTP_200_OK: TokenSerializer()},
tags=["auth"],
)
@action(
methods=["PATCH"],
Expand Down Expand Up @@ -245,14 +284,18 @@ def get_parameters(self, request):
return token, user_id

@swagger_auto_schema(
methods=["POST"], responses={status.HTTP_200_OK: TokenSerializer()}
operation_id="api_account_resetPassword_request",
methods=["POST"],
responses={status.HTTP_200_OK: TokenSerializer()},
tags=["auth"],
)
@action(
methods=["POST"],
detail=False,
serializer_class=ResetPasswordRequestSerializer,
url_path="request",
)
def request(self, request, *args, **kwargs):
def request_reset(self, request, *args, **kwargs):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags were not generated properly for this one (defaulting to api). Probably because behind of that inheritance there is already a self.request used for another thing and @swagger_auto_schema was not detecting the tag correctly. So the workaround would be to preserve the same path by using url_path and renaming the method.

serializer = ResetPasswordRequestSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
email = serializer.validated_data["email"]
Expand Down Expand Up @@ -288,6 +331,7 @@ def request(self, request, *args, **kwargs):
},
),
},
tags=["auth"],
)
@action(methods=["GET"], detail=False)
def validate(self, request, *args, **kwargs):
Expand Down Expand Up @@ -318,6 +362,7 @@ def validate(self, request, *args, **kwargs):
},
),
},
tags=["auth"],
)
@action(
methods=["PATCH"], detail=False, serializer_class=ResetPasswordConfirmSerializer
Expand Down
22 changes: 21 additions & 1 deletion estela-api/api/views/cronjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ def get_queryset(self):
description="Cron job tag.",
),
],
tags=["spider-cronjobs"],
)
def list(self, *args, **kwargs):
return super(SpiderCronJobViewSet, self).list(*args, **kwargs)

@swagger_auto_schema(
request_body=SpiderCronJobCreateSerializer,
responses={status.HTTP_201_CREATED: SpiderCronJobCreateSerializer()},
tags=["spider-cronjobs"],
)
def create(self, request, *args, **kwargs):
spider = get_object_or_404(Spider, sid=self.kwargs["sid"], deleted=False)
Expand Down Expand Up @@ -101,6 +103,7 @@ def create(self, request, *args, **kwargs):
@swagger_auto_schema(
request_body=SpiderCronJobUpdateSerializer,
responses={status.HTTP_200_OK: SpiderCronJobUpdateSerializer()},
tags=["spider-cronjobs"],
)
def update(self, request, *args, **kwargs):
partial = kwargs.pop("partial", False)
Expand All @@ -118,6 +121,7 @@ def update(self, request, *args, **kwargs):

@swagger_auto_schema(
responses={status.HTTP_204_NO_CONTENT: "Cronjob deleted"},
tags=["spider-cronjobs"],
)
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
Expand All @@ -131,7 +135,9 @@ def perform_destroy(self, instance):
instance.save()

@swagger_auto_schema(
methods=["GET"], responses={status.HTTP_200_OK: SpiderCronJobSerializer()}
methods=["GET"],
responses={status.HTTP_200_OK: SpiderCronJobSerializer()},
tags=["spider-cronjobs"],
)
@action(methods=["GET"], detail=True)
def run_once(self, request, *args, **kwargs):
Expand All @@ -142,3 +148,17 @@ def run_once(self, request, *args, **kwargs):

run_cronjob_once(cronjob.data)
return Response(cronjob.data, status=status.HTTP_200_OK)

@swagger_auto_schema(
responses={status.HTTP_200_OK: SpiderCronJobSerializer()},
tags=["spider-cronjobs"],
)
def retrieve(self, request, *args, **kwargs):
return super().retrieve(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: SpiderCronJobSerializer()},
tags=["spider-cronjobs"],
)
def partial_update(self, request, *args, **kwargs):
return super().partial_update(request, *args, **kwargs)
32 changes: 32 additions & 0 deletions estela-api/api/views/deploy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.shortcuts import get_object_or_404
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import viewsets, status
from rest_framework.response import Response
Expand Down Expand Up @@ -40,6 +41,7 @@ def get_queryset(self):
@swagger_auto_schema(
request_body=DeployCreateSerializer,
responses={status.HTTP_201_CREATED: DeployCreateSerializer()},
tags=["deploys"],
)
def create(self, request, *args, **kwargs):
project = get_object_or_404(Project, pid=self.kwargs["pid"])
Expand Down Expand Up @@ -74,6 +76,7 @@ def create(self, request, *args, **kwargs):
@swagger_auto_schema(
request_body=DeployUpdateSerializer,
responses={status.HTTP_200_OK: DeployUpdateSerializer()},
tags=["deploys"],
)
def update(self, request, *args, **kwargs):
if not request.user.is_superuser:
Expand All @@ -93,3 +96,32 @@ def update(self, request, *args, **kwargs):

headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_200_OK, headers=headers)

@swagger_auto_schema(
tags=["deploys"],
)
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: DeploySerializer()},
tags=["deploys"],
)
def retrieve(self, request, *args, **kwargs):
return super().retrieve(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: DeploySerializer()},
tags=["deploys"],
)
def partial_update(self, request, *args, **kwargs):
return super().partial_update(request, *args, **kwargs)

@swagger_auto_schema(
responses={
status.HTTP_204_NO_CONTENT: openapi.Response("No Content"),
},
tags=["deploys"],
)
def destroy(self, request, *args, **kwargs):
return super().destroy(request, *args, **kwargs)
18 changes: 17 additions & 1 deletion estela-api/api/views/job.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import date, timedelta
from django.shortcuts import get_object_or_404
from django_filters.rest_framework import DjangoFilterBackend
from drf_yasg.utils import swagger_auto_schema
Expand Down Expand Up @@ -80,6 +79,7 @@ def get_queryset(self):
description="Job tag.",
),
],
tags=["spider-jobs"],
)
def list(self, *args, **kwargs):
return super(SpiderJobViewSet, self).list(*args, **kwargs)
Expand All @@ -95,6 +95,7 @@ def list(self, *args, **kwargs):
],
request_body=SpiderJobCreateSerializer,
responses={status.HTTP_201_CREATED: SpiderJobCreateSerializer()},
tags=["spider-jobs"],
)
def create(self, request, *args, **kwargs):
spider = get_object_or_404(Spider, sid=self.kwargs["sid"], deleted=False)
Expand Down Expand Up @@ -146,6 +147,7 @@ def create(self, request, *args, **kwargs):
@swagger_auto_schema(
request_body=SpiderJobUpdateSerializer,
responses={status.HTTP_200_OK: SpiderJobUpdateSerializer()},
tags=["spider-jobs"],
)
def update(self, request, *args, **kwargs):
partial = kwargs.pop("partial", False)
Expand All @@ -161,3 +163,17 @@ def update(self, request, *args, **kwargs):

headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_200_OK, headers=headers)

@swagger_auto_schema(
responses={status.HTTP_200_OK: SpiderJobSerializer()},
tags=["spider-jobs"],
)
def retrieve(self, request, *args, **kwargs):
return super().retrieve(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: SpiderJobSerializer()},
tags=["spider-jobs"],
)
def partial_update(self, request, *args, **kwargs):
return super().partial_update(request, *args, **kwargs)
2 changes: 2 additions & 0 deletions estela-api/api/views/job_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def get_paginated_link(self, page_number):
required=False,
),
],
tags=["spider-jobs"],
)
def list(self, request, *args, **kwargs):
page, data_type, page_size = self.get_parameters(request)
Expand Down Expand Up @@ -161,6 +162,7 @@ def list(self, request, *args, **kwargs):
required=True,
),
],
tags=["spider-jobs"],
)
@action(methods=["POST"], detail=False)
def delete(self, request, *args, **kwargs):
Expand Down
33 changes: 33 additions & 0 deletions estela-api/api/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def perform_create(self, serializer):
@swagger_auto_schema(
request_body=ProjectUpdateSerializer,
responses={status.HTTP_200_OK: ProjectUpdateSerializer()},
tags=["projects"],
)
def update(self, request, *args, **kwargs):
partial = kwargs.pop("partial", False)
Expand Down Expand Up @@ -137,6 +138,7 @@ def update(self, request, *args, **kwargs):

@swagger_auto_schema(
responses={status.HTTP_204_NO_CONTENT: "Project deleted"},
tags=["projects"],
)
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
Expand Down Expand Up @@ -166,6 +168,7 @@ def perform_destroy(self, instance):
),
],
responses={status.HTTP_200_OK: ProjectJobSerializer()},
tags=["projects"],
)
@action(methods=["GET"], detail=True)
def jobs(self, request, *args, **kwargs):
Expand Down Expand Up @@ -205,6 +208,7 @@ def jobs(self, request, *args, **kwargs):
),
],
responses={status.HTTP_200_OK: ProjectCronJobSerializer()},
tags=["projects"],
)
@action(methods=["GET"], detail=True)
def cronjobs(self, request, *args, **kwargs):
Expand All @@ -227,6 +231,7 @@ def cronjobs(self, request, *args, **kwargs):
@swagger_auto_schema(
methods=["GET"],
responses={status.HTTP_200_OK: ProjectUsageSerializer()},
tags=["projects"],
)
@action(methods=["GET"], detail=True)
def current_usage(self, request, *args, **kwargs):
Expand Down Expand Up @@ -258,6 +263,7 @@ def current_usage(self, request, *args, **kwargs):
),
],
responses={status.HTTP_200_OK: UsageRecordSerializer(many=True)},
tags=["projects"],
)
@action(methods=["GET"], detail=True)
def usage(self, request, *args, **kwargs):
Expand All @@ -276,3 +282,30 @@ def usage(self, request, *args, **kwargs):
serializer.data,
status=status.HTTP_200_OK,
)

@swagger_auto_schema(
tags=["projects"],
)
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: ProjectSerializer()},
tags=["projects"],
)
def retrieve(self, request, *args, **kwargs):
return super().retrieve(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_201_CREATED: ProjectSerializer()},
tags=["projects"],
)
def create(self, request, *args, **kwargs):
return super().create(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: ProjectSerializer()},
tags=["projects"],
)
def partial_update(self, request, *args, **kwargs):
return super().partial_update(request, *args, **kwargs)
Loading