Skip to content

Commit ea8e6f4

Browse files
committed
improve swagger docs
1 parent 664bc6e commit ea8e6f4

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

gateway/api/v1/views/jobs.py

+59
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Jobs view api for V1.
33
"""
44

5+
from drf_yasg import openapi
56
from drf_yasg.utils import swagger_auto_schema
67
from rest_framework import permissions, status
78
from rest_framework.decorators import action
@@ -72,6 +73,64 @@ def result(self, request, pk=None):
7273

7374
@swagger_auto_schema(
7475
operation_description="Update the sub status of a job",
76+
request_body=openapi.Schema(
77+
type=openapi.TYPE_OBJECT,
78+
required=["sub_status"],
79+
properties={
80+
"sub_status": openapi.Schema(type=openapi.TYPE_STRING)
81+
},
82+
description="Value to populate the sub-status of a Job"
83+
),
84+
responses={
85+
status.HTTP_200_OK: openapi.Response(
86+
description="In case everything is ok.",
87+
schema=openapi.Schema(
88+
type=openapi.TYPE_OBJECT,
89+
properties={
90+
"message": openapi.Schema(
91+
type=openapi.TYPE_STRING,
92+
example="Sub status updated correctly"
93+
)
94+
}
95+
)
96+
),
97+
status.HTTP_400_BAD_REQUEST: openapi.Response(
98+
description="In case your request doesnt have a valid 'sub_status'.",
99+
schema=openapi.Schema(
100+
type=openapi.TYPE_OBJECT,
101+
properties={
102+
"message": openapi.Schema(
103+
type=openapi.TYPE_STRING,
104+
example="'sub_status' not provided or is not valid"
105+
)
106+
}
107+
)
108+
),
109+
status.HTTP_403_FORBIDDEN: openapi.Response(
110+
description="In case you cannot change the sub_status.",
111+
schema=openapi.Schema(
112+
type=openapi.TYPE_OBJECT,
113+
properties={
114+
"message": openapi.Schema(
115+
type=openapi.TYPE_STRING,
116+
example="Cannot update 'sub_status' when is not in RUNNING status. (Currently PENDING)"
117+
)
118+
}
119+
)
120+
),
121+
status.HTTP_404_NOT_FOUND: openapi.Response(
122+
description="In case the job doesnt exist or you dont have access to it.",
123+
schema=openapi.Schema(
124+
type=openapi.TYPE_OBJECT,
125+
properties={
126+
"message": openapi.Schema(
127+
type=openapi.TYPE_STRING,
128+
example="Job [XXXX] not found"
129+
)
130+
}
131+
)
132+
)
133+
},
75134
)
76135
@action(methods=["POST"], detail=True)
77136
def sub_status(self, request, pk=None):

0 commit comments

Comments
 (0)