refactor: Migrate users.register endpoint to OpenAPI with AJV validation
Closed
AM
6mo ago+153+153+012345678901234567890123456789-123-123-012345678901234567890123456789
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 existingusersEndpointsvariable - Added local
UserRegisterParamsPOSTtype,UserRegisterParamsPostSchema, andisUserRegisterParamsPOSTvalidator (moved from rest-typings) - Added
body: isUserRegisterParamsPOSTreplacing deprecatedvalidateParams - Added response validation schemas:
200with$ref: '#/components/schemas/IUser'via Typia400withvalidateBadRequestErrorResponse
- Used
async function action()named handler (not arrow function) - Fixed error handling in
validateCustomFieldscatch block to passe.messageinstead of raw error object - Excluded sensitive fields (
services,inviteToken) from the returned user object via projection - Handled
inactiveReason: nullfrom the database by deleting the property whennullto satisfy Typia schema validation (same workaround asusers.create) - Business logic, permissions, and side effects are completely unchanged
packages/rest-typings/src/v1/users.ts
- Removed
/v1/users.registerentry from theUsersEndpointsinterface (now auto-generated viaExtractRoutesFromAPI) - 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 theusers.registerendpoint type for theweb-ui-registrationpackage, which depends on it for registration form typing
.changeset/migrate-users-register-openapi.md
- Added changeset with
minorbump for@rocket.chat/meteor,@rocket.chat/rest-typings, and@rocket.chat/web-ui-registration
Test results
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.