Skip to content
Merged
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/migrate-rooms-leave-endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/meteor': minor
'@rocket.chat/rest-typings': minor
---

Migrated rooms.leave endpoint to new OpenAPI pattern with AJV validation
Comment on lines +1 to +6
Copy link
Copy Markdown
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab Feb 24, 2026

Choose a reason for hiding this comment

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

you need to add the rest-types, because you have done changes there

'@rocket.chat/rest-typings': patch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ahmed-n-abdeltwab I've done that now

79 changes: 62 additions & 17 deletions apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,23 +390,6 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'rooms.leave',
{ authRequired: true },
{
async post() {
const room = await findRoomByIdOrName({ params: this.bodyParams });
const user = await Users.findOneById(this.userId);
if (!user) {
return API.v1.failure('Invalid user');
}
await leaveRoomMethod(user, room._id);

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

/*
TO-DO: 8.0.0 should use the ajv validation
which will change this endpoint's
Expand Down Expand Up @@ -935,6 +918,14 @@ type RoomsFavorite =
favorite: boolean;
};

type RoomsLeave =
| {
roomId: string;
}
| {
roomName: string;
};

const isRoomGetRolesPropsSchema = {
type: 'object',
properties: {
Expand Down Expand Up @@ -967,7 +958,29 @@ const RoomsFavoriteSchema = {
],
};

const isRoomsLeavePropsSchema = {
anyOf: [
{
type: 'object',
properties: {
roomId: { type: 'string' },
},
required: ['roomId'],
additionalProperties: false,
},
{
type: 'object',
properties: {
roomName: { type: 'string' },
},
required: ['roomName'],
additionalProperties: false,
},
],
};

const isRoomsFavoriteProps = ajv.compile<RoomsFavorite>(RoomsFavoriteSchema);
const isRoomsLeaveProps = ajv.compile<RoomsLeave>(isRoomsLeavePropsSchema);

export const roomEndpoints = API.v1
.get(
Expand Down Expand Up @@ -1141,6 +1154,38 @@ export const roomEndpoints = API.v1

await toggleFavoriteMethod(this.userId, room._id, favorite);

return API.v1.success();
},
)
.post(
'rooms.leave',
{
authRequired: true,
body: isRoomsLeaveProps,
response: {
200: ajv.compile<void>({
type: 'object',
properties: {
success: { type: 'boolean', enum: [true] },
},
required: ['success'],
additionalProperties: false,
}),
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
},
},
async function action() {
const room = await findRoomByIdOrName({ params: this.bodyParams });

const user = await Users.findOneById(this.userId);

if (!user) {
return API.v1.failure('error-invalid-user');
}

await leaveRoomMethod(user, room._id);

return API.v1.success();
},
);
Expand Down
5 changes: 0 additions & 5 deletions packages/rest-typings/src/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const isRoomsAutocompleteAdminRoomsPayload = ajv.compile<RoomsAutocomplet

type BaseRoomsProps = { roomId: string } | { roomName: string };
type RoomsInfoProps = BaseRoomsProps;
type RoomsLeaveProps = BaseRoomsProps;

const RoomsInfoSchema = {
oneOf: [
Expand Down Expand Up @@ -822,10 +821,6 @@ export type RoomsEndpoints = {
};
};

'/v1/rooms.leave': {
POST: (params: RoomsLeaveProps) => void;
};

'/v1/rooms.getDiscussions': {
GET: (params: RoomsGetDiscussionsProps) => PaginatedResult<{
discussions: IRoom[];
Expand Down
Loading