From d5db1e417129ba6dacc0e5fd04814430dbde2031 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Wed, 19 Apr 2023 16:28:05 +0530 Subject: [PATCH] Swagger/booking req resp body (#256) --- pages/api/bookings/[id]/_get.ts | 24 ++++++++- pages/api/bookings/[id]/_patch.ts | 30 ++++++++++- pages/api/bookings/_get.ts | 28 +++++++++- pages/api/bookings/_post.ts | 87 +++++++++++++++++++++++++------ 4 files changed, 150 insertions(+), 19 deletions(-) diff --git a/pages/api/bookings/[id]/_get.ts b/pages/api/bookings/[id]/_get.ts index 2d6ae07a64..5064ba2d78 100644 --- a/pages/api/bookings/[id]/_get.ts +++ b/pages/api/bookings/[id]/_get.ts @@ -32,7 +32,29 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform * content: * application/json: * schema: - * $ref: "#/components/schemas/Booking" + * $ref: "#/components/schemas/ArrayOfBookings" + * examples: + * bookings: + * value: [ + * { + * "id": 1, + * "description": "Meeting with John", + * "eventTypeId": 2, + * "uid": "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8", + * "title": "Business Meeting", + * "startTime": "2023-04-20T10:00:00.000Z", + * "endTime": "2023-04-20T11:00:00.000Z", + * "timeZone": "Europe/London", + * "attendees": [ + * { + * "email": "example@cal.com", + * "name": "John Doe", + * "timeZone": "Europe/London", + * "locale": "en" + * } + * ] + * } + * ] * 401: * description: Authorization information is missing or invalid. * 404: diff --git a/pages/api/bookings/[id]/_patch.ts b/pages/api/bookings/[id]/_patch.ts index 8c1638e2a4..74999ab13c 100644 --- a/pages/api/bookings/[id]/_patch.ts +++ b/pages/api/bookings/[id]/_patch.ts @@ -35,6 +35,15 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform * status: * type: string * description: 'Acceptable values one of ["ACCEPTED", "PENDING", "CANCELLED", "REJECTED"]' + * examples: + * editBooking: + * value: + * { + * "title": "Debugging between Syed Ali Shahbaz and Hello Hello", + * "start": "2023-05-24T13:00:00.000Z", + * "end": "2023-05-24T13:30:00.000Z", + * "status": "CANCELLED" + * } * * parameters: * - in: query @@ -52,8 +61,27 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform * tags: * - bookings * responses: - * 201: + * 200: * description: OK, booking edited successfully + * content: + * application/json: + * examples: + * bookings: + * value: + * { + * "booking": { + * "id": 11223344, + * "userId": 182, + * "description": null, + * "eventTypeId": 2323232, + * "uid": "stoSJtnh83PEL4rZmqdHe2", + * "title": "Debugging between Syed Ali Shahbaz and Hello Hello", + * "startTime": "2023-05-24T13:00:00.000Z", + * "endTime": "2023-05-24T13:30:00.000Z", + * "metadata": {}, + * "status": "CANCELLED" + * } + * } * 400: * description: Bad request. Booking body is invalid. * 401: diff --git a/pages/api/bookings/_get.ts b/pages/api/bookings/_get.ts index e610f42103..006b39472e 100644 --- a/pages/api/bookings/_get.ts +++ b/pages/api/bookings/_get.ts @@ -19,15 +19,18 @@ import { schemaQuerySingleOrMultipleUserIds } from "~/lib/validations/shared/que * schema: * type: string * description: Your API key + * example: 123456789abcdefgh * - in: query * name: userId * required: false * schema: * oneOf: * - type: integer + * example: 1 * - type: array * items: * type: integer + * example: [2, 3, 4] * operationId: listBookings * tags: * - bookings @@ -38,11 +41,34 @@ import { schemaQuerySingleOrMultipleUserIds } from "~/lib/validations/shared/que * application/json: * schema: * $ref: "#/components/schemas/ArrayOfBookings" + * examples: + * bookings: + * value: [ + * { + * "id": 1, + * "description": "Meeting with John", + * "eventTypeId": 2, + * "uid": "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8", + * "title": "Business Meeting", + * "startTime": "2023-04-20T10:00:00.000Z", + * "endTime": "2023-04-20T11:00:00.000Z", + * "timeZone": "Europe/London", + * "attendees": [ + * { + * "email": "example@cal.com", + * "name": "John Doe", + * "timeZone": "Europe/London", + * "locale": "en" + * } + * ] + * } + * ] * 401: - * description: Authorization information is missing or invalid. + * description: Authorization information is missing or invalid. * 404: * description: No bookings were found */ + async function handler(req: NextApiRequest) { const { userId, isAdmin, prisma } = req; const args: Prisma.BookingFindManyArgs = {}; diff --git a/pages/api/bookings/_post.ts b/pages/api/bookings/_post.ts index 3f9c17978d..d6baaa4891 100644 --- a/pages/api/bookings/_post.ts +++ b/pages/api/bookings/_post.ts @@ -90,27 +90,82 @@ import { defaultResponder } from "@calcom/lib/server"; * smsReminderNumber: * type: number * description: 'SMS reminder number' - * examples: - * New Booking example: - * value: - * { - * "eventTypeId": 1, - * "start": "2023-05-01T14:00:00Z", - * "end": "2023-05-01T15:00:00Z", - * "name": "John Doe", - * "email": "john.doe@example.com", - * "timeZone": "America/New_York", - * "language": "en-US", - * "metadata": {}, - * "customInputs": [], - * "location": "Conference Room A" - * } + * examples: + * New Booking example: + * value: + * { + * "eventTypeId": 2323232, + * "start": "2023-05-24T13:00:00.000Z", + * "end": "2023-05-24T13:30:00.000Z", + * "name": "Hello Hello", + * "email": "hello@gmail.com", + * "timeZone": "Europe/London", + * "language": "en", + * "metadata": {}, + * "customInputs": [], + * "location": "Calcom HQ", + * "title": "Debugging between Syed Ali Shahbaz and Hello Hello", + * "description": null, + * "status": "PENDING", + * "smsReminderNumber": null + * } * * tags: * - bookings * responses: - * 201: + * 200: * description: Booking(s) created successfully. + * content: + * application/json: + * examples: + * bookings: + * value: + * { + * "id": 11223344, + * "uid": "5yUjmAYTDF6MXo98re8SkX", + * "userId": 123, + * "eventTypeId": 2323232, + * "title": "Debugging between Syed Ali Shahbaz and Hello Hello", + * "description": null, + * "customInputs": {}, + * "responses": null, + * "startTime": "2023-05-24T13:00:00.000Z", + * "endTime": "2023-05-24T13:30:00.000Z", + * "location": "Calcom HQ", + * "createdAt": "2023-04-19T10:17:58.580Z", + * "updatedAt": null, + * "status": "PENDING", + * "paid": false, + * "destinationCalendarId": 2180, + * "cancellationReason": null, + * "rejectionReason": null, + * "dynamicEventSlugRef": null, + * "dynamicGroupSlugRef": null, + * "rescheduled": null, + * "fromReschedule": null, + * "recurringEventId": null, + * "smsReminderNumber": null, + * "scheduledJobs": [], + * "metadata": {}, + * "isRecorded": false, + * "user": { + * "email": "test@cal.com", + * "name": "Syed Ali Shahbaz", + * "timeZone": "Asia/Calcutta" + * }, + * "attendees": [ + * { + * "id": 12345, + * "email": "hello@gmail.com", + * "name": "Hello Hello", + * "timeZone": "Europe/London", + * "locale": "en", + * "bookingId": 11223344 + * } + * ], + * "payment": [], + * "references": [] + * } * 400: * description: | * Bad request