Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/nice-squids-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/rest-typings": patch
---

Add OpenAPI support for the Rocket.Chat e2e.getUsersOfRoomWithoutKey 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.
124 changes: 86 additions & 38 deletions apps/meteor/app/api/server/v1/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { IUser } from '@rocket.chat/core-typings';
import { Subscriptions, Users } from '@rocket.chat/models';
import {
ajv,
validateUnauthorizedErrorResponse,
validateBadRequestErrorResponse,
ise2eGetUsersOfRoomWithoutKeyParamsGET,
ise2eSetUserPublicAndPrivateKeysParamsPOST,
ise2eUpdateGroupKeyParamsPOST,
isE2EProvideUsersGroupKeyProps,
Expand Down Expand Up @@ -34,6 +34,10 @@ type E2eSetRoomKeyIdProps = {
keyID: string;
};

type e2eGetUsersOfRoomWithoutKeyParamsGET = {
rid: string;
};

const E2eSetRoomKeyIdSchema = {
type: 'object',
properties: {
Expand All @@ -48,60 +52,104 @@ const E2eSetRoomKeyIdSchema = {
additionalProperties: false,
};

const e2eGetUsersOfRoomWithoutKeyParamsGETSchema = {
type: 'object',
properties: {
rid: {
type: 'string',
},
},
additionalProperties: false,
required: ['rid'],
};

const isE2eSetRoomKeyIdProps = ajv.compile<E2eSetRoomKeyIdProps>(E2eSetRoomKeyIdSchema);

const e2eEndpoints = API.v1.post(
'e2e.setRoomKeyID',
{
authRequired: true,
body: isE2eSetRoomKeyIdProps,
response: {
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
200: ajv.compile<void>({
type: 'object',
properties: {
success: { type: 'boolean', enum: [true] },
},
required: ['success'],
}),
const ise2eGetUsersOfRoomWithoutKeyParamsGET = ajv.compile<e2eGetUsersOfRoomWithoutKeyParamsGET>(
e2eGetUsersOfRoomWithoutKeyParamsGETSchema,
);

const e2eEndpoints = API.v1
.post(
'e2e.setRoomKeyID',
{
authRequired: true,
body: isE2eSetRoomKeyIdProps,
response: {
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
200: ajv.compile<void>({
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.getUsersOfRoomWithoutKey',
{
authRequired: true,
query: ise2eGetUsersOfRoomWithoutKeyParamsGET,
response: {
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
200: ajv.compile<{
users: Pick<IUser, '_id' | 'e2e'>[];
}>({
type: 'object',
properties: {
users: {
type: 'array',
items: {
type: 'object',
properties: {
_id: { type: 'string' },
e2e: {
type: 'object',
properties: {
private_key: { type: 'string' },
public_key: { type: 'string' },
},
},
},
required: ['_id'],
},
},
success: { type: 'boolean', enum: [true] },
},
required: ['users', 'success'],
}),
},
},

API.v1.addRoute(
'e2e.fetchMyKeys',
{
authRequired: true,
},
{
async get() {
const result = await Users.fetchKeysByUserId(this.userId);
async function action() {
const { rid } = this.queryParams;

const result = await getUsersOfRoomWithoutKeyMethod(this.userId, rid);

return API.v1.success(result);
},
},
);
);

API.v1.addRoute(
'e2e.getUsersOfRoomWithoutKey',
'e2e.fetchMyKeys',
{
authRequired: true,
validateParams: ise2eGetUsersOfRoomWithoutKeyParamsGET,
},
{
async get() {
const { rid } = this.queryParams;

const result = await getUsersOfRoomWithoutKeyMethod(this.userId, rid);
const result = await Users.fetchKeysByUserId(this.userId);

return API.v1.success(result);
},
Expand Down
1 change: 0 additions & 1 deletion packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ export * from './v1/server-events';
export * from './v1/autotranslate/AutotranslateGetSupportedLanguagesParamsGET';
export * from './v1/autotranslate/AutotranslateSaveSettingsParamsPOST';
export * from './v1/autotranslate/AutotranslateTranslateMessageParamsPOST';
export * from './v1/e2e/e2eGetUsersOfRoomWithoutKeyParamsGET';
export * from './v1/e2e/e2eSetUserPublicAndPrivateKeysParamsPOST';
export * from './v1/e2e/e2eUpdateGroupKeyParamsPOST';
export * from './v1/e2e';
Expand Down
5 changes: 0 additions & 5 deletions packages/rest-typings/src/v1/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ export type E2eEndpoints = {
'/v1/e2e.setUserPublicAndPrivateKeys': {
POST: (params: E2eSetUserPublicAndPrivateKeysProps) => void;
};
'/v1/e2e.getUsersOfRoomWithoutKey': {
GET: (params: E2eGetUsersOfRoomWithoutKeyProps) => {
users: Pick<IUser, '_id' | 'e2e'>[];
};
};
'/v1/e2e.updateGroupKey': {
POST: (params: E2eUpdateGroupKeyProps) => void;
};
Expand Down

This file was deleted.

Loading