Skip to content

Commit 2a27010

Browse files
chore: Add OpenAPI support for the Rocket.Chat e2e.updateGroupKey endpoints (#39094)
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
1 parent d8baf39 commit 2a27010

File tree

5 files changed

+56
-106
lines changed

5 files changed

+56
-106
lines changed

.changeset/pretty-jobs-juggle.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rocket.chat/rest-typings': minor
3+
'@rocket.chat/meteor': minor
4+
---
5+
6+
Adds OpenAPI support for the Rocket.Chat e2e.updateGroupKey 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.

apps/meteor/app/api/server/v1/e2e.ts

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
validateUnauthorizedErrorResponse,
66
validateBadRequestErrorResponse,
77
ise2eSetUserPublicAndPrivateKeysParamsPOST,
8-
ise2eUpdateGroupKeyParamsPOST,
98
isE2EProvideUsersGroupKeyProps,
109
isE2EFetchUsersWaitingForGroupKeyProps,
1110
isE2EResetRoomKeyProps,
@@ -38,6 +37,12 @@ type e2eGetUsersOfRoomWithoutKeyParamsGET = {
3837
rid: string;
3938
};
4039

40+
type e2eUpdateGroupKeyParamsPOST = {
41+
uid: string;
42+
rid: string;
43+
key: string;
44+
};
45+
4146
const E2eSetRoomKeyIdSchema = {
4247
type: 'object',
4348
properties: {
@@ -63,12 +68,31 @@ const e2eGetUsersOfRoomWithoutKeyParamsGETSchema = {
6368
required: ['rid'],
6469
};
6570

71+
const e2eUpdateGroupKeyParamsPOSTSchema = {
72+
type: 'object',
73+
properties: {
74+
uid: {
75+
type: 'string',
76+
},
77+
rid: {
78+
type: 'string',
79+
},
80+
key: {
81+
type: 'string',
82+
},
83+
},
84+
additionalProperties: false,
85+
required: ['uid', 'rid', 'key'],
86+
};
87+
6688
const isE2eSetRoomKeyIdProps = ajv.compile<E2eSetRoomKeyIdProps>(E2eSetRoomKeyIdSchema);
6789

6890
const ise2eGetUsersOfRoomWithoutKeyParamsGET = ajv.compile<e2eGetUsersOfRoomWithoutKeyParamsGET>(
6991
e2eGetUsersOfRoomWithoutKeyParamsGETSchema,
7092
);
7193

94+
const ise2eUpdateGroupKeyParamsPOST = ajv.compile<e2eUpdateGroupKeyParamsPOST>(e2eUpdateGroupKeyParamsPOSTSchema);
95+
7296
const e2eEndpoints = API.v1
7397
.post(
7498
'e2e.setRoomKeyID',
@@ -165,6 +189,31 @@ const e2eEndpoints = API.v1
165189

166190
return API.v1.success(result);
167191
},
192+
)
193+
.post(
194+
'e2e.updateGroupKey',
195+
{
196+
authRequired: true,
197+
body: ise2eUpdateGroupKeyParamsPOST,
198+
response: {
199+
400: validateBadRequestErrorResponse,
200+
401: validateUnauthorizedErrorResponse,
201+
200: ajv.compile<void>({
202+
type: 'object',
203+
properties: {
204+
success: { type: 'boolean', enum: [true] },
205+
},
206+
required: ['success'],
207+
}),
208+
},
209+
},
210+
async function action() {
211+
const { uid, rid, key } = this.bodyParams;
212+
213+
await updateGroupKey(rid, uid, key, this.userId);
214+
215+
return API.v1.success();
216+
},
168217
);
169218

170219
/**
@@ -222,56 +271,6 @@ API.v1.addRoute(
222271
},
223272
);
224273

225-
/**
226-
* @openapi
227-
* /api/v1/e2e.updateGroupKey:
228-
* post:
229-
* description: Updates the end-to-end encryption key for a user on a room
230-
* security:
231-
* - autenticated: {}
232-
* requestBody:
233-
* description: A tuple containing the user ID, the room ID, and the key
234-
* content:
235-
* application/json:
236-
* schema:
237-
* type: object
238-
* properties:
239-
* uid:
240-
* type: string
241-
* rid:
242-
* type: string
243-
* key:
244-
* type: string
245-
* responses:
246-
* 200:
247-
* content:
248-
* application/json:
249-
* schema:
250-
* $ref: '#/components/schemas/ApiSuccessV1'
251-
* default:
252-
* description: Unexpected error
253-
* content:
254-
* application/json:
255-
* schema:
256-
* $ref: '#/components/schemas/ApiFailureV1'
257-
*/
258-
API.v1.addRoute(
259-
'e2e.updateGroupKey',
260-
{
261-
authRequired: true,
262-
validateParams: ise2eUpdateGroupKeyParamsPOST,
263-
},
264-
{
265-
async post() {
266-
const { uid, rid, key } = this.bodyParams;
267-
268-
await updateGroupKey(rid, uid, key, this.userId);
269-
270-
return API.v1.success();
271-
},
272-
},
273-
);
274-
275274
API.v1.addRoute(
276275
'e2e.acceptSuggestedGroupKey',
277276
{

packages/rest-typings/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ export * from './v1/server-events';
244244
export * from './v1/autotranslate/AutotranslateGetSupportedLanguagesParamsGET';
245245
export * from './v1/autotranslate/AutotranslateSaveSettingsParamsPOST';
246246
export * from './v1/e2e/e2eSetUserPublicAndPrivateKeysParamsPOST';
247-
export * from './v1/e2e/e2eUpdateGroupKeyParamsPOST';
248247
export * from './v1/e2e';
249248
export * from './v1/import';
250249
export * from './v1/email-inbox';

packages/rest-typings/src/v1/e2e.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,6 @@ const E2eGetUsersOfRoomWithoutKeySchema = {
3939

4040
export const isE2eGetUsersOfRoomWithoutKeyProps = ajv.compile<E2eGetUsersOfRoomWithoutKeyProps>(E2eGetUsersOfRoomWithoutKeySchema);
4141

42-
type E2eUpdateGroupKeyProps = {
43-
uid: string;
44-
rid: string;
45-
key: string;
46-
};
47-
48-
const E2eUpdateGroupKeySchema = {
49-
type: 'object',
50-
properties: {
51-
uid: {
52-
type: 'string',
53-
},
54-
rid: {
55-
type: 'string',
56-
},
57-
key: {
58-
type: 'string',
59-
},
60-
},
61-
required: ['uid', 'rid', 'key'],
62-
additionalProperties: false,
63-
};
64-
65-
export const isE2eUpdateGroupKeyProps = ajv.compile<E2eUpdateGroupKeyProps>(E2eUpdateGroupKeySchema);
66-
6742
type E2EProvideUsersGroupKeyProps = {
6843
usersSuggestedGroupKeys: Record<IRoom['_id'], { _id: IUser['_id']; key: string; oldKeys: ISubscription['suggestedOldRoomKeys'] }[]>;
6944
};
@@ -149,9 +124,6 @@ export type E2eEndpoints = {
149124
'/v1/e2e.setUserPublicAndPrivateKeys': {
150125
POST: (params: E2eSetUserPublicAndPrivateKeysProps) => void;
151126
};
152-
'/v1/e2e.updateGroupKey': {
153-
POST: (params: E2eUpdateGroupKeyProps) => void;
154-
};
155127
'/v1/e2e.acceptSuggestedGroupKey': {
156128
POST: (params: E2eGetUsersOfRoomWithoutKeyProps) => void;
157129
};

packages/rest-typings/src/v1/e2e/e2eUpdateGroupKeyParamsPOST.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)