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

Merged
VE
7mo ago
+68-22

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.

COMM-144
Task: ARCH-1987