Skip to content

chore: migrate rooms.leave endpoint to new OpenAPI pattern with AJV validation#38957

Merged
ggazzo merged 11 commits intoRocketChat:developfrom
Verifieddanny:refactor/migrate-rooms-leave-endpoint
Feb 25, 2026
Merged

chore: migrate rooms.leave endpoint to new OpenAPI pattern with AJV validation#38957
ggazzo merged 11 commits intoRocketChat:developfrom
Verifieddanny:refactor/migrate-rooms-leave-endpoint

Conversation

@Verifieddanny
Copy link
Contributor

@Verifieddanny Verifieddanny commented Feb 23, 2026

Proposed changes (including videos or screenshots)

Migrates the rooms.leave endpoint from the legacy API.v1.addRoute
pattern to the new OpenAPI-compliant format using AJV schema validation,
continuing the REST API migration effort.

Tracked in: RocketChat/Rocket.Chat-Open-API#150

Key changes:

  • Replaced API.v1.addRoute with chained .post() for rooms.leave
  • Added declarative AJV body schema with anyOf constraint supporting
    either roomId or roomName
  • Added explicit response schemas for 200, 400, and 401 status codes
  • Removed manually written type from packages/rest-typings/src/v1/rooms.ts
    since it is now auto-generated via ExtractRoutesFromAPI
  • Added changeset file
  • Business logic unchanged

Swagger UI — endpoint documented at /api-docs/:

Screenshot from 2026-02-24 00-31-14

400 response — validation and business logic working correctly:

Screenshot from 2026-02-24 00-31-30

Steps to test or reproduce

  1. Run the server locally with yarn dev
  2. Navigate to http://localhost:3000/api-docs/
  3. Authorize with X-Auth-Token and X-User-Id
  4. Find POST /api/v1/rooms.leave
  5. Execute with valid body: { "roomName": "general" }
  6. Execute with empty body {} to confirm 400 validation error

Further comments

Follows the same migration pattern established in #35995 (rooms.favorite).

Summary by CodeRabbit

  • Chores
    • Migrated the rooms.leave API to a new validated endpoint for more robust request handling and clearer error responses.
  • Documentation
    • Added a release changeset noting the patch bump and the endpoint migration.

Task: ARCH-1987

@Verifieddanny Verifieddanny requested review from a team as code owners February 23, 2026 23:40
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 23, 2026

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

🦋 Changeset detected

Latest commit: 1605bcc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/meteor Minor
@rocket.chat/rest-typings Minor
@rocket.chat/api-client Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/models Patch
@rocket.chat/ui-contexts Major
@rocket.chat/web-ui-registration Major
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/livechat Patch
@rocket.chat/mock-providers Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch
@rocket.chat/ui-client Major
@rocket.chat/media-calls Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/gazzodown Major
@rocket.chat/ui-avatar Major
@rocket.chat/ui-video-conf Major
@rocket.chat/ui-voip Major
@rocket.chat/core-typings Minor
@rocket.chat/apps Patch
@rocket.chat/model-typings Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

Walkthrough

The rooms.leave endpoint was migrated from the legacy API.v1.addRoute implementation to an OpenAPI-style route using AJV request validation, with a new RoomsLeave union type, compiled validator, and the route integrated into the existing roomEndpoints chain.

Changes

Cohort / File(s) Summary
Changeset Documentation
\.changeset/migrate-rooms-leave-endpoint.md
Added changeset recording a patch bump and noting migration of rooms.leave to OpenAPI/AJV validation.
Endpoint Migration
apps/meteor/app/api/server/v1/rooms.ts
Removed legacy rooms.leave addRoute; added `type RoomsLeave = { roomId: string }
Typings Cleanup
packages/rest-typings/src/v1/rooms.ts
Removed deprecated RoomsLeaveProps alias and the explicit /v1/rooms.leave endpoint mapping from RoomsEndpoints to reflect auto-generated route typings via ExtractRoutesFromAPI.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant APIv1 as API.v1 rooms.leave
  participant AJV as AJV Validator
  participant Rooms as Room Resolver
  participant Users as User Service
  participant Method as leaveRoomMethod

  Client->>APIv1: POST /api/v1/rooms.leave {roomId|roomName}
  APIv1->>AJV: validate(body)
  AJV-->>APIv1: valid / invalid
  alt valid
    APIv1->>Rooms: resolve room by id or name
    Rooms-->>APIv1: room (or not found)
    APIv1->>Users: fetch user by request auth
    Users-->>APIv1: user (or not found)
    APIv1->>Method: leaveRoomMethod(user, room)
    Method-->>APIv1: result
    APIv1-->>Client: 200 { success: true }
  else invalid
    APIv1-->>Client: 400 validation error
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through schemas, nimble and spry,
AJV caught errors before they could fly.
Rooms leave the old path, new route in the sun,
One small patch, and the migration is done!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—migrating rooms.leave endpoint to OpenAPI pattern with AJV validation—and clearly summarizes the primary modification in the changeset.
Linked Issues check ✅ Passed All objectives from ARCH-1987 are met: endpoint migrated to chained .post() with AJV schema validation, anyOf constraint for roomId/roomName, response schemas for 200/400/401, legacy type removed, changeset added.
Out of Scope Changes check ✅ Passed All changes are directly related to the rooms.leave endpoint migration objective; no unrelated modifications are present in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Copy link
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab left a comment

Choose a reason for hiding this comment

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

LGTM

@ahmed-n-abdeltwab
Copy link
Contributor

@ggazzo 👍

Comment on lines +1 to +5
---
'@rocket.chat/meteor': patch
---

Migrated rooms.leave endpoint to new OpenAPI pattern with AJV validation
Copy link
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
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

@ggazzo ggazzo changed the title refactor: migrate rooms.leave endpoint to new OpenAPI pattern with AJV validation chore: migrate rooms.leave endpoint to new OpenAPI pattern with AJV validation Feb 24, 2026
@ggazzo ggazzo added this to the 8.3.0 milestone Feb 24, 2026
@ggazzo
Copy link
Member

ggazzo commented Feb 24, 2026

/jira ARCH-1935

@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Feb 24, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Feb 24, 2026
@dionisio-bot dionisio-bot bot enabled auto-merge February 24, 2026 13:52
@Verifieddanny
Copy link
Contributor Author

@ggazzo just made the changeset changes from patch to minor
Thank you

@ggazzo
Copy link
Member

ggazzo commented Feb 24, 2026

If you keep syncing with develop, I can't add it to the queue.

@Verifieddanny
Copy link
Contributor Author

Ohh alright, noted moving forward 🫡

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.67%. Comparing base (55bf071) to head (1605bcc).
⚠️ Report is 16 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38957      +/-   ##
===========================================
+ Coverage    70.64%   70.67%   +0.03%     
===========================================
  Files         3189     3189              
  Lines       112716   112716              
  Branches     20413    20434      +21     
===========================================
+ Hits         79632    79667      +35     
+ Misses       31040    31007      -33     
+ Partials      2044     2042       -2     
Flag Coverage Δ
unit 71.24% <ø> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ggazzo ggazzo disabled auto-merge February 25, 2026 04:41
@ggazzo ggazzo merged commit 4025314 into RocketChat:develop Feb 25, 2026
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

Development

Successfully merging this pull request may close these issues.

3 participants