refactor: Migrate users.register endpoint to OpenAPI with AJV validation

Closed
AM
6mo ago
+153-123

Proposed changes

Migrates the users.register endpoint from the legacy addRoute() pattern to the new OpenAPI-compatible chained route pattern with inline AJV validation schemas.

Resolves: RocketChat/Rocket.Chat-Open-API#150

Changes

apps/meteor/app/api/server/v1/users.ts

  • Replaced legacy API.v1.addRoute('users.register', ...) with the new chained .post('users.register', ...) pattern on the existing usersEndpoints variable
  • Added local UserRegisterParamsPOST type, UserRegisterParamsPostSchema, and isUserRegisterParamsPOST validator (moved from rest-typings)
  • Added body: isUserRegisterParamsPOST replacing deprecated validateParams
  • Added response validation schemas:
    • 200 with $ref: '#/components/schemas/IUser' via Typia
    • 400 with validateBadRequestErrorResponse
  • Used async function action() named handler (not arrow function)
  • Fixed error handling in validateCustomFields catch block to pass e.message instead of raw error object
  • Excluded sensitive fields (services, inviteToken) from the returned user object via projection
  • Handled inactiveReason: null from the database by deleting the property when null to satisfy Typia schema validation (same workaround as users.create)
  • Business logic, permissions, and side effects are completely unchanged

packages/rest-typings/src/v1/users.ts

  • Removed /v1/users.register entry from the UsersEndpoints interface (now auto-generated via ExtractRoutesFromAPI)
  • Removed import type { UserRegisterParamsPOST } and its re-export (no longer needed in this file)

packages/rest-typings/src/v1/users/UserRegisterParamsPOST.ts

  • Deleted entirely β€” the AJV schema, compiled validator, and type are now defined locally in the endpoint file

packages/web-ui-registration/src/users-register.d.ts

  • Added declare module '@rocket.chat/rest-typings' augmentation to re-expose the users.register endpoint type for the web-ui-registration package, which depends on it for registration form typing

.changeset/migrate-users-register-openapi.md

  • Added changeset with minor bump for @rocket.chat/meteor, @rocket.chat/rest-typings, and @rocket.chat/web-ui-registration

Test results

image

Summary by CodeRabbit

  • New Features

    • Added OpenAPI support for the user registration endpoint.
  • Refactor

    • Improved registration validation and error messages, with more reliable handling of custom fields and normalization of inactive reason.
  • Chores

    • Minor version bumps for registration-related packages.