From f02cfc99906c93767e1f6edd4a0f33fc51a4cc98 Mon Sep 17 00:00:00 2001
From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
Date: Mon, 13 Feb 2023 18:22:11 +0530
Subject: [PATCH] Swagger definition general fixes (#237)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This PR addresses definition errors currently residing within our
swagger doc.
~DISCLAIMER: There is still an error for our DELETE booking call, as
open API standard doesn't expect the DELETE call to contain a request
body, but we are requiring it in the way it currently works. Perhaps we
should move those to Query Parameters instead. Thoughts @zomars @emrysal
?~
It was taken care of by @leog and the docs are now updated as per the
endpoint
---------
Co-authored-by: Leo Giovanetti
Co-authored-by: Omar López
---
.../shared/queryIdTransformParseInt.ts | 11 +---
pages/api/booking-references/[id]/_delete.ts | 8 ++-
pages/api/booking-references/[id]/_get.ts | 8 ++-
pages/api/booking-references/[id]/_patch.ts | 27 ++++++---
pages/api/booking-references/_get.ts | 9 ++-
pages/api/booking-references/_post.ts | 37 ++++++++-----
pages/api/bookings/[id]/_delete.ts | 55 +++++++++----------
pages/api/bookings/_get.ts | 23 +++-----
pages/api/users/_post.ts | 2 +-
9 files changed, 101 insertions(+), 79 deletions(-)
diff --git a/lib/validations/shared/queryIdTransformParseInt.ts b/lib/validations/shared/queryIdTransformParseInt.ts
index b97d126d43..b9ec495f47 100644
--- a/lib/validations/shared/queryIdTransformParseInt.ts
+++ b/lib/validations/shared/queryIdTransformParseInt.ts
@@ -5,14 +5,9 @@ import { baseApiParams } from "./baseApiParams";
// Extracted out as utility function so can be reused
// at different endpoints that require this validation.
-export const schemaQueryIdParseInt = baseApiParams
- .extend({
- id: z
- .string()
- .regex(/^\d+$/)
- .transform((id) => parseInt(id)),
- })
- .strict();
+export const schemaQueryIdParseInt = baseApiParams.extend({
+ id: z.coerce.number(),
+});
export const withValidQueryIdTransformParseInt = withValidation({
schema: schemaQueryIdParseInt,
diff --git a/pages/api/booking-references/[id]/_delete.ts b/pages/api/booking-references/[id]/_delete.ts
index 54160b0124..23a83ce311 100644
--- a/pages/api/booking-references/[id]/_delete.ts
+++ b/pages/api/booking-references/[id]/_delete.ts
@@ -17,8 +17,14 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* type: integer
* required: true
* description: ID of the booking reference to delete
+ * - in: query
+ * name: apiKey
+ * required: true
+ * schema:
+ * type: string
+ * description: Your API key
* tags:
- * - booking-references
+ * - booking-references
* responses:
* 201:
* description: OK, bookingReference removed successfully
diff --git a/pages/api/booking-references/[id]/_get.ts b/pages/api/booking-references/[id]/_get.ts
index 2ea3bd68c5..6baf71a550 100644
--- a/pages/api/booking-references/[id]/_get.ts
+++ b/pages/api/booking-references/[id]/_get.ts
@@ -18,8 +18,14 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* type: integer
* required: true
* description: ID of the booking reference to get
+ * - in: query
+ * name: apiKey
+ * required: true
+ * schema:
+ * type: string
+ * description: Your API key
* tags:
- * - booking-references
+ * - booking-references
* responses:
* 200:
* description: OK
diff --git a/pages/api/booking-references/[id]/_patch.ts b/pages/api/booking-references/[id]/_patch.ts
index c235370255..37e17e2e00 100644
--- a/pages/api/booking-references/[id]/_patch.ts
+++ b/pages/api/booking-references/[id]/_patch.ts
@@ -23,16 +23,25 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* schema:
* type: object
* properties:
- * days:
- * type: array
- * example: email@example.com
- * startTime:
+ * type:
* type: string
- * example: 1970-01-01T17:00:00.000Z
- * endTime:
+ * meetingId:
* type: string
- * example: 1970-01-01T17:00:00.000Z
+ * meetingPassword:
+ * type: string
+ * externalCalendarId:
+ * type: string
+ * deleted:
+ * type: boolean
+ * credentialId:
+ * type: integer
* parameters:
+ * - in: query
+ * name: apiKey
+ * required: true
+ * schema:
+ * type: string
+ * description: Your API key
* - in: path
* name: id
* schema:
@@ -40,10 +49,10 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* required: true
* description: ID of the booking reference to edit
* tags:
- * - booking-references
+ * - booking-references
* responses:
* 201:
- * description: OK, safeBody.data edited successfully
+ * description: OK, BookingReference edited successfully
* 400:
* description: Bad request. BookingReference body is invalid.
* 401:
diff --git a/pages/api/booking-references/_get.ts b/pages/api/booking-references/_get.ts
index 5934d4ef03..c3b81a4622 100644
--- a/pages/api/booking-references/_get.ts
+++ b/pages/api/booking-references/_get.ts
@@ -9,10 +9,17 @@ import { schemaBookingReferenceReadPublic } from "~/lib/validations/booking-refe
* @swagger
* /booking-references:
* get:
+ * parameters:
+ * - in: query
+ * name: apiKey
+ * required: true
+ * schema:
+ * type: string
+ * description: Your API key
* operationId: listBookingReferences
* summary: Find all booking references
* tags:
- * - booking-references
+ * - booking-references
* responses:
* 200:
* description: OK
diff --git a/pages/api/booking-references/_post.ts b/pages/api/booking-references/_post.ts
index ff9f0109aa..b3b8b713cf 100644
--- a/pages/api/booking-references/_post.ts
+++ b/pages/api/booking-references/_post.ts
@@ -12,6 +12,13 @@ import {
* @swagger
* /booking-references:
* post:
+ * parameters:
+ * - in: query
+ * name: apiKey
+ * required: true
+ * schema:
+ * type: string
+ * description: Your API key
* operationId: addBookingReference
* summary: Creates a new booking reference
* requestBody:
@@ -24,27 +31,27 @@ import {
* required:
* - type
* - uid
- * - meetingId
- * - bookingId
- * - deleted
* properties:
- * deleted:
- * type: boolean
- * example: false
- * uid:
- * type: string
- * example: '123456789'
* type:
* type: string
- * example: email@example.com
- * bookingId:
- * type: number
- * example: 1
+ * uid:
+ * type: string
* meetingId:
* type: string
- * example: 'meeting-id'
+ * meetingPassword:
+ * type: string
+ * meetingUrl:
+ * type: string
+ * bookingId:
+ * type: boolean
+ * externalCalendarId:
+ * type: string
+ * deleted:
+ * type: boolean
+ * credentialId:
+ * type: integer
* tags:
- * - booking-references
+ * - booking-references
* responses:
* 201:
* description: OK, booking reference created
diff --git a/pages/api/bookings/[id]/_delete.ts b/pages/api/bookings/[id]/_delete.ts
index c2bc3cf5d9..a1cdbc9c3e 100644
--- a/pages/api/bookings/[id]/_delete.ts
+++ b/pages/api/bookings/[id]/_delete.ts
@@ -12,16 +12,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* delete:
* summary: Booking cancellation
* operationId: cancelBookingById
- * requestBody:
- * content:
- * application/json:
- * schema:
- * type: object
- * properties:
- * allRemainingBookings:
- * type: boolean
- * reason:
- * type: string
+ *
* parameters:
* - in: path
* name: id
@@ -29,24 +20,29 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* type: integer
* required: true
* description: ID of the booking to cancel
- * parameters:
- * - in: path
- * name: id
- * schema:
- * type: integer
- * required: true
- * description: ID of the booking to get
- * - in: query
- * name: apiKey
- * required: true
- * schema:
- * type: string
- * description: Your API key
+ * - in: query
+ * name: apiKey
+ * required: true
+ * schema:
+ * type: string
+ * description: Your API key
+ * - in: query
+ * name: allRemainingBookings
+ * required: false
+ * schema:
+ * type: boolean
+ * description: Delete all remaining bookings
+ * - in: query
+ * name: reason
+ * required: false
+ * schema:
+ * type: string
+ * description: The reason for cancellation of the booking
* tags:
* - bookings
* responses:
* 200:
- * description: OK, booking cancelled successfuly
+ * description: OK, booking cancelled successfully
* 400:
* description: |
* Bad request
@@ -72,11 +68,12 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* description: User not found
*/
async function handler(req: NextApiRequest) {
- const { id } = schemaQueryIdParseInt.parse(req.query);
- const { allRemainingBookings, cancellationReason } = schemaBookingCancelParams.parse({
- ...req.body,
- cancellationReason: req.body.reason,
- });
+ const { id, allRemainingBookings, cancellationReason } = schemaQueryIdParseInt
+ .merge(schemaBookingCancelParams.pick({ allRemainingBookings: true, cancellationReason: true }))
+ .parse({
+ ...req.query,
+ allRemainingBookings: req.query.allRemainingBookings === "true",
+ });
// Normalizing for universal handler
req.body = { id, allRemainingBookings, cancellationReason };
return await handleCancelBooking(req);
diff --git a/pages/api/bookings/_get.ts b/pages/api/bookings/_get.ts
index 9476d07e09..a9158c22b3 100644
--- a/pages/api/bookings/_get.ts
+++ b/pages/api/bookings/_get.ts
@@ -19,21 +19,16 @@ import { schemaQuerySingleOrMultipleUserIds } from "~/lib/validations/shared/que
* schema:
* type: string
* description: Your API key
+ * - in: query
+ * name: userId
+ * required: false
+ * schema:
+ * oneOf:
+ * - type: integer
+ * - type: array
+ * items:
+ * type: integer
* operationId: listBookings
- * requestBody:
- * description: Find all bookings
- * content:
- * application/json:
- * schema:
- * type: object
- * properties:
- * userId:
- * description: 'The user(s) to get the booking for, if the request is by an Admin'
- * oneOf:
- * - type: integer
- * - type: array
- * items:
- * type: integer
* tags:
* - bookings
* responses:
diff --git a/pages/api/users/_post.ts b/pages/api/users/_post.ts
index 3ee8c222d5..7c945399d0 100644
--- a/pages/api/users/_post.ts
+++ b/pages/api/users/_post.ts
@@ -46,7 +46,7 @@ import { schemaUserCreateBodyParams } from "~/lib/validations/user";
* description: Start of the week. Acceptable values are one of [SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY]
* type: string
* timeZone:
- * description: The new user's time zone. Eg: 'EUROPE/PARIS'
+ * description: The new user's time zone. Eg- 'EUROPE/PARIS'
* type: string
* theme:
* description: Default theme for the new user. Acceptable values are one of [DARK, LIGHT]