From 38987b77bb82089edf869dfc3b09e1e96625192a Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Thu, 20 Apr 2023 00:52:07 +0530 Subject: [PATCH] Swagger/schedules request and response examples (#257) This PR adds request body and response body examples to swagger in /schedules endpoint Added for: - [x] `/schedules/_post` - [x] `/schedules/_get` - [x] `/schedules/[id]/_get` - [x] `/schedules/[id]/_post` - [x] `/schedules/[id]/_patch` --- pages/api/schedules/[id]/_get.ts | 37 +++++++++++++++++++++++++++ pages/api/schedules/[id]/_patch.ts | 36 ++++++++++++++++++++++++--- pages/api/schedules/_get.ts | 40 ++++++++++++++++++++++++++++++ pages/api/schedules/_post.ts | 39 ++++++++++++++++++++++++++--- 4 files changed, 145 insertions(+), 7 deletions(-) diff --git a/pages/api/schedules/[id]/_get.ts b/pages/api/schedules/[id]/_get.ts index 27502833fd..fdadce2cba 100644 --- a/pages/api/schedules/[id]/_get.ts +++ b/pages/api/schedules/[id]/_get.ts @@ -29,11 +29,48 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform * responses: * 200: * description: OK + * content: + * application/json: + * examples: + * schedule: + * value: + * { + * "schedule": { + * "id": 12345, + * "userId": 182, + * "name": "Sample Schedule", + * "timeZone": "Asia/Calcutta", + * "availability": [ + * { + * "id": 111, + * "eventTypeId": null, + * "days": [0, 1, 2, 3, 4, 6], + * "startTime": "00:00:00", + * "endTime": "23:45:00" + * }, + * { + * "id": 112, + * "eventTypeId": null, + * "days": [5], + * "startTime": "00:00:00", + * "endTime": "12:00:00" + * }, + * { + * "id": 113, + * "eventTypeId": null, + * "days": [5], + * "startTime": "15:00:00", + * "endTime": "23:45:00" + * } + * ] + * } + * } * 401: * description: Authorization information is missing or invalid. * 404: * description: Schedule was not found */ + export async function getHandler(req: NextApiRequest) { const { prisma, query } = req; const { id } = schemaQueryIdParseInt.parse(query); diff --git a/pages/api/schedules/[id]/_patch.ts b/pages/api/schedules/[id]/_patch.ts index 85c67e91c0..1c8f52d688 100644 --- a/pages/api/schedules/[id]/_patch.ts +++ b/pages/api/schedules/[id]/_patch.ts @@ -27,7 +27,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform * required: true * description: Your API Key * requestBody: - * description: Create a new schedule + * description: Edit an existing schedule * required: true * content: * application/json: @@ -37,19 +37,49 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform * name: * type: string * description: Name of the schedule - * timezone: + * timeZone: * type: string * description: The timezone for this schedule + * examples: + * schedule: + * value: + * { + * "name": "Updated Schedule", + * "timeZone": "Asia/Calcutta" + * } * tags: * - schedules * responses: - * 201: + * 200: * description: OK, schedule edited successfully + * content: + * application/json: + * examples: + * schedule: + * value: + * { + * "schedule": { + * "id": 12345, + * "userId": 1, + * "name": "Total Testing Part 2", + * "timeZone": "Asia/Calcutta", + * "availability": [ + * { + * "id": 4567, + * "eventTypeId": null, + * "days": [1, 2, 3, 4, 5], + * "startTime": "09:00:00", + * "endTime": "17:00:00" + * } + * ] + * } + * } * 400: * description: Bad request. Schedule body is invalid. * 401: * description: Authorization information is missing or invalid. */ + export async function patchHandler(req: NextApiRequest) { const { prisma, query } = req; const { id } = schemaQueryIdParseInt.parse(query); diff --git a/pages/api/schedules/_get.ts b/pages/api/schedules/_get.ts index 4790780835..1b06a116e9 100644 --- a/pages/api/schedules/_get.ts +++ b/pages/api/schedules/_get.ts @@ -30,11 +30,51 @@ export const schemaUserIds = z * responses: * 200: * description: OK + * content: + * application/json: + * examples: + * schedules: + * value: + * { + * "schedules": [ + * { + * "id": 1234, + * "userId": 5678, + * "name": "Sample Schedule 1", + * "timeZone": "America/Chicago", + * "availability": [ + * { + * "id": 987, + * "eventTypeId": null, + * "days": [1, 2, 3, 4, 5], + * "startTime": "09:00:00", + * "endTime": "23:00:00" + * } + * ] + * }, + * { + * "id": 2345, + * "userId": 6789, + * "name": "Sample Schedule 2", + * "timeZone": "Europe/Amsterdam", + * "availability": [ + * { + * "id": 876, + * "eventTypeId": null, + * "days": [1, 2, 3, 4, 5], + * "startTime": "09:00:00", + * "endTime": "17:00:00" + * } + * ] + * } + * ] + * } * 401: * description: Authorization information is missing or invalid. * 404: * description: No schedules were found */ + async function handler(req: NextApiRequest) { const { prisma, userId, isAdmin } = req; const args: Prisma.ScheduleFindManyArgs = isAdmin ? {} : { where: { userId } }; diff --git a/pages/api/schedules/_post.ts b/pages/api/schedules/_post.ts index 03c1fb0b6e..a50f2cd5b6 100644 --- a/pages/api/schedules/_post.ts +++ b/pages/api/schedules/_post.ts @@ -29,24 +29,55 @@ import { schemaCreateScheduleBodyParams, schemaSchedulePublic } from "~/lib/vali * type: object * required: * - name - * - timezone + * - timeZone * properties: * name: * type: string * description: Name of the schedule - * timezone: + * timeZone: * type: string - * description: The timezone for this schedule + * description: The timeZone for this schedule + * examples: + * schedule: + * value: + * { + * "name": "Sample Schedule", + * "timeZone": "Asia/Calcutta" + * } * tags: * - schedules * responses: - * 201: + * 200: * description: OK, schedule created + * content: + * application/json: + * examples: + * schedule: + * value: + * { + * "schedule": { + * "id": 79471, + * "userId": 182, + * "name": "Total Testing", + * "timeZone": "Asia/Calcutta", + * "availability": [ + * { + * "id": 337917, + * "eventTypeId": null, + * "days": [1, 2, 3, 4, 5], + * "startTime": "09:00:00", + * "endTime": "17:00:00" + * } + * ] + * }, + * "message": "Schedule created successfully" + * } * 400: * description: Bad request. Schedule body is invalid. * 401: * description: Authorization information is missing or invalid. */ + async function postHandler(req: NextApiRequest) { const { userId, isAdmin, prisma } = req; const body = schemaCreateScheduleBodyParams.parse(req.body);