diff --git a/.changeset/short-starfishes-provide.md b/.changeset/short-starfishes-provide.md new file mode 100644 index 0000000000000..8dd7878bca54e --- /dev/null +++ b/.changeset/short-starfishes-provide.md @@ -0,0 +1,6 @@ +--- +"@rocket.chat/meteor": patch +"@rocket.chat/rest-typings": patch +--- + +Add OpenAPI support for the Rocket.Chat e2e.fetchMyKeys endpoints by migrating to a modern chained route definition syntax and utilizing shared AJV schemas for validation to enhance API documentation and ensure type safety through response validation. diff --git a/apps/meteor/app/api/server/v1/e2e.ts b/apps/meteor/app/api/server/v1/e2e.ts index 3686f2a7b9007..1e91289f62e46 100644 --- a/apps/meteor/app/api/server/v1/e2e.ts +++ b/apps/meteor/app/api/server/v1/e2e.ts @@ -50,46 +50,59 @@ const E2eSetRoomKeyIdSchema = { const isE2eSetRoomKeyIdProps = ajv.compile(E2eSetRoomKeyIdSchema); -const e2eEndpoints = API.v1.post( - 'e2e.setRoomKeyID', - { - authRequired: true, - body: isE2eSetRoomKeyIdProps, - response: { - 400: validateBadRequestErrorResponse, - 401: validateUnauthorizedErrorResponse, - 200: ajv.compile({ - type: 'object', - properties: { - success: { type: 'boolean', enum: [true] }, - }, - required: ['success'], - }), +const e2eEndpoints = API.v1 + .post( + 'e2e.setRoomKeyID', + { + authRequired: true, + body: isE2eSetRoomKeyIdProps, + response: { + 400: validateBadRequestErrorResponse, + 401: validateUnauthorizedErrorResponse, + 200: ajv.compile({ + type: 'object', + properties: { + success: { type: 'boolean', enum: [true] }, + }, + required: ['success'], + }), + }, }, - }, - async function action() { - const { rid, keyID } = this.bodyParams; + async function action() { + const { rid, keyID } = this.bodyParams; - await setRoomKeyIDMethod(this.userId, rid, keyID); + await setRoomKeyIDMethod(this.userId, rid, keyID); - return API.v1.success(); - }, -); + return API.v1.success(); + }, + ) + .get( + 'e2e.fetchMyKeys', + { + authRequired: true, + query: undefined, + response: { + 400: validateBadRequestErrorResponse, + 401: validateUnauthorizedErrorResponse, + 200: ajv.compile<{ public_key: string; private_key: string }>({ + type: 'object', + properties: { + public_key: { type: 'string' }, + private_key: { type: 'string' }, + success: { type: 'boolean', enum: [true] }, + }, + required: ['success'], + }), + }, + }, -API.v1.addRoute( - 'e2e.fetchMyKeys', - { - authRequired: true, - }, - { - async get() { - const result = await Users.fetchKeysByUserId(this.userId); + async function action() { + const result = (await Users.fetchKeysByUserId(this.userId)) as unknown as { public_key: string; private_key: string }; return API.v1.success(result); }, - }, -); + ); API.v1.addRoute( 'e2e.getUsersOfRoomWithoutKey', diff --git a/packages/rest-typings/src/v1/e2e.ts b/packages/rest-typings/src/v1/e2e.ts index 7c7bd8a1d1a66..2fa8b4f472b6a 100644 --- a/packages/rest-typings/src/v1/e2e.ts +++ b/packages/rest-typings/src/v1/e2e.ts @@ -166,9 +166,6 @@ export type E2eEndpoints = { '/v1/e2e.rejectSuggestedGroupKey': { POST: (params: E2eGetUsersOfRoomWithoutKeyProps) => void; }; - '/v1/e2e.fetchMyKeys': { - GET: () => { public_key: string; private_key: string }; - }; '/v1/e2e.fetchUsersWaitingForGroupKey': { GET: (params: E2EFetchUsersWaitingForGroupKeyProps) => { usersWaitingForE2EKeys: Record;