Skip to content

Commit

Permalink
Improve estela generated OpenAPI documentation
Browse files Browse the repository at this point in the history
Update swagger host in estela api settings.
Add tags to estela api endpoints.
  • Loading branch information
johann2357 committed Apr 17, 2023
1 parent d14d7b3 commit 3cc024c
Show file tree
Hide file tree
Showing 22 changed files with 3,246 additions and 1,470 deletions.
17 changes: 14 additions & 3 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 Down Expand Up @@ -149,6 +153,7 @@ def get_queryset(self):

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

@swagger_auto_schema(
responses={status.HTTP_200_OK: UserProfileSerializer()},
tags=["auth", "profile"],
)
def update(self, request, *args, **kwargs):
username = kwargs.get("username", "")
Expand Down Expand Up @@ -201,6 +207,7 @@ class ChangePasswordViewSet(viewsets.GenericViewSet):
@swagger_auto_schema(
request_body=ChangePasswordSerializer,
responses={status.HTTP_200_OK: TokenSerializer()},
tags=["account"],
)
@action(
methods=["PATCH"],
Expand Down Expand Up @@ -245,7 +252,9 @@ def get_parameters(self, request):
return token, user_id

@swagger_auto_schema(
methods=["POST"], responses={status.HTTP_200_OK: TokenSerializer()}
methods=["POST"],
responses={status.HTTP_200_OK: TokenSerializer()},
tags=["account"],
)
@action(
methods=["POST"],
Expand Down Expand Up @@ -288,6 +297,7 @@ def request(self, request, *args, **kwargs):
},
),
},
tags=["account"],
)
@action(methods=["GET"], detail=False)
def validate(self, request, *args, **kwargs):
Expand Down Expand Up @@ -318,6 +328,7 @@ def validate(self, request, *args, **kwargs):
},
),
},
tags=["account"],
)
@action(
methods=["PATCH"], detail=False, serializer_class=ResetPasswordConfirmSerializer
Expand Down
8 changes: 7 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=["project", "spider", "cronjob"],
)
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=["project", "spider", "cronjob"],
)
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=["project", "spider", "cronjob"],
)
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=["project", "spider", "cronjob"],
)
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=["project", "spider", "cronjob"],
)
@action(methods=["GET"], detail=True)
def run_once(self, request, *args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions estela-api/api/views/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def get_queryset(self):
@swagger_auto_schema(
request_body=DeployCreateSerializer,
responses={status.HTTP_201_CREATED: DeployCreateSerializer()},
tags=["project", "deploy"],
)
def create(self, request, *args, **kwargs):
project = get_object_or_404(Project, pid=self.kwargs["pid"])
Expand Down Expand Up @@ -74,6 +75,7 @@ def create(self, request, *args, **kwargs):
@swagger_auto_schema(
request_body=DeployUpdateSerializer,
responses={status.HTTP_200_OK: DeployUpdateSerializer()},
tags=["project", "deploy"],
)
def update(self, request, *args, **kwargs):
if not request.user.is_superuser:
Expand Down
3 changes: 3 additions & 0 deletions estela-api/api/views/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def get_queryset(self):
description="Job tag.",
),
],
tags=["project", "spider", "job"],
)
def list(self, *args, **kwargs):
return super(SpiderJobViewSet, self).list(*args, **kwargs)
Expand All @@ -95,6 +96,7 @@ def list(self, *args, **kwargs):
],
request_body=SpiderJobCreateSerializer,
responses={status.HTTP_201_CREATED: SpiderJobCreateSerializer()},
tags=["project", "spider", "job"],
)
def create(self, request, *args, **kwargs):
spider = get_object_or_404(Spider, sid=self.kwargs["sid"], deleted=False)
Expand Down Expand Up @@ -146,6 +148,7 @@ def create(self, request, *args, **kwargs):
@swagger_auto_schema(
request_body=SpiderJobUpdateSerializer,
responses={status.HTTP_200_OK: SpiderJobUpdateSerializer()},
tags=["project", "spider", "job"],
)
def update(self, request, *args, **kwargs):
partial = kwargs.pop("partial", False)
Expand Down
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 @@ -85,6 +85,7 @@ def get_paginated_link(self, page_number):
required=False,
),
],
tags=["project", "spider", "job", "job-data"],
)
def list(self, request, *args, **kwargs):
page, data_type, mode, page_size = self.get_parameters(request)
Expand Down Expand Up @@ -188,6 +189,7 @@ def list(self, request, *args, **kwargs):
required=True,
),
],
tags=["project", "spider", "job", "job-data"],
)
@action(methods=["POST"], detail=False)
def delete(self, request, *args, **kwargs):
Expand Down
6 changes: 6 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=["project"],
)
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=["project"],
)
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=["project"],
)
@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=["project"],
)
@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=["project"],
)
@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=["project"],
)
@action(methods=["GET"], detail=True)
def usage(self, request, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions estela-api/api/views/spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def get_queryset(self):
@swagger_auto_schema(
request_body=SpiderUpdateSerializer,
responses={status.HTTP_200_OK: SpiderUpdateSerializer()},
tags=["project", "spider"],
)
def update(self, request, *args, **kwargs):
partial = kwargs.pop("partial", False)
Expand Down
2 changes: 1 addition & 1 deletion estela-api/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
SWAGGER_SETTINGS = {
"DEFAULT_INFO": "docs.settings.api_info",
"DEFAULT_GENERATOR_CLASS": "docs.settings.APISchemeGenerator",
"DEFAULT_API_URL": "http://127.0.0.1:8000",
"DEFAULT_API_URL": "https://api.cloud.bitmaker.dev/api/",
}

# AWS configurations
Expand Down
Loading

0 comments on commit 3cc024c

Please sign in to comment.