Skip to content

Commit

Permalink
Add OpenAPI tags for inherited methods
Browse files Browse the repository at this point in the history
In the past all of those were tagged as `api`, instead we are giving the
correct tags according to its url path.
  • Loading branch information
johann2357 committed Apr 21, 2023
1 parent 67cf664 commit fd13959
Show file tree
Hide file tree
Showing 18 changed files with 1,950 additions and 972 deletions.
36 changes: 35 additions & 1 deletion estela-api/api/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,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 @@ -202,6 +205,35 @@ def update(self, request, *args, **kwargs):
serializer.save()
return Response(data=serializer.data, status=status.HTTP_200_OK)

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

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

@swagger_auto_schema(
responses={status.HTTP_200_OK: UserProfileSerializer()},
tags=["auth", "profile"],
)
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", "profile"],
)
def destroy(self, request, *args, **kwargs):
return super().destroy(request, *args, **kwargs)


class ChangePasswordViewSet(viewsets.GenericViewSet):
@swagger_auto_schema(
Expand Down Expand Up @@ -252,6 +284,7 @@ def get_parameters(self, request):
return token, user_id

@swagger_auto_schema(
operation_id="api_account_resetPassword_request",
methods=["POST"],
responses={status.HTTP_200_OK: TokenSerializer()},
tags=["account"],
Expand All @@ -260,8 +293,9 @@ def get_parameters(self, request):
methods=["POST"],
detail=False,
serializer_class=ResetPasswordRequestSerializer,
url_path="request",
)
def request(self, request, *args, **kwargs):
def request_reset(self, request, *args, **kwargs):
serializer = ResetPasswordRequestSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
email = serializer.validated_data["email"]
Expand Down
14 changes: 14 additions & 0 deletions estela-api/api/views/cronjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,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=["project", "spider", "cronjob"],
)
def retrieve(self, request, *args, **kwargs):
return super().retrieve(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: SpiderCronJobSerializer()},
tags=["project", "spider", "cronjob"],
)
def partial_update(self, request, *args, **kwargs):
return super().partial_update(request, *args, **kwargs)
30 changes: 30 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 @@ -95,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=["project", "deploy"],
)
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)

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

@swagger_auto_schema(
responses={status.HTTP_200_OK: DeploySerializer()},
tags=["project", "deploy"],
)
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=["project", "deploy"],
)
def destroy(self, request, *args, **kwargs):
return super().destroy(request, *args, **kwargs)
15 changes: 14 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 @@ -164,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=["project", "spider", "job"],
)
def retrieve(self, request, *args, **kwargs):
return super().retrieve(request, *args, **kwargs)

@swagger_auto_schema(
responses={status.HTTP_200_OK: SpiderJobSerializer()},
tags=["project", "spider", "job"],
)
def partial_update(self, request, *args, **kwargs):
return super().partial_update(request, *args, **kwargs)
27 changes: 27 additions & 0 deletions estela-api/api/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,30 @@ def usage(self, request, *args, **kwargs):
serializer.data,
status=status.HTTP_200_OK,
)

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

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

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

@swagger_auto_schema(
responses={status.HTTP_200_OK: ProjectSerializer()},
tags=["project"],
)
def partial_update(self, request, *args, **kwargs):
return super().partial_update(request, *args, **kwargs)
20 changes: 20 additions & 0 deletions estela-api/api/views/spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ def update(self, request, *args, **kwargs):
instance._prefetched_objects_cache = {}

return Response(serializer.data, status=status.HTTP_200_OK)

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

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

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

0 comments on commit fd13959

Please sign in to comment.