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/short-starfishes-provide.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.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.
77 changes: 45 additions & 32 deletions apps/meteor/app/api/server/v1/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,59 @@ const E2eSetRoomKeyIdSchema = {

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 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.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 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is as unknown as needed when it wasn't before? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fetchKeysByUserId function was returning { public_key: string; private_key: string } | object from the database, but in both the backend and frontend it was expected to return only { public_key: string; private_key: string }. I updated it to keep the return type consistent with the backend and frontend


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

API.v1.addRoute(
'e2e.getUsersOfRoomWithoutKey',
Expand Down
3 changes: 0 additions & 3 deletions packages/rest-typings/src/v1/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRoom['_id'], { _id: IUser['_id']; public_key: string }[]>;
Expand Down
Loading