Skip to content

feat(api): migrate users.getPreferences to OpenAPI pattern#38325

Open
Mohamed-Sobea wants to merge 4 commits intoRocketChat:developfrom
Mohamed-Sobea:feat/migrate-users-getPreferences
Open

feat(api): migrate users.getPreferences to OpenAPI pattern#38325
Mohamed-Sobea wants to merge 4 commits intoRocketChat:developfrom
Mohamed-Sobea:feat/migrate-users-getPreferences

Conversation

@Mohamed-Sobea
Copy link

@Mohamed-Sobea Mohamed-Sobea commented Jan 24, 2026

Description:

This PR completes the migration of the users.getPreferences endpoint to the new OpenAPI + AJV pattern. It introduces robust schema validation for responses, improves type safety by utilizing ExtractRoutesFromAPI, and ensures the endpoint is fully documented and verified within the Swagger UI.

Key Changes:

Full Migration: Moved users.getPreferences to the new API pattern with compiled AJV validation.

Swagger Documentation: Included the response block in the route definition to enable automatic documentation generation in the API Explorer.

Typing Cleanup: Purged legacy manual interfaces and endpoint types from packages/rest-typings to ensure a single source of truth via ExtractRoutesFromAPI.

Linting & Formatting: Resolved all spacing and formatting issues by running yarn lint -- --fix.

Testing & Verification:

Swagger UI: Verified at /api-docs/. The schema correctly reflects the validated response structure.

Functional Test: Successfully authorized and executed the endpoint in the Swagger explorer, receiving a 200 OK with the expected user preferences.

E2E Tests: Ran yarn testapi --grep users.getPreferences in apps/meteor; all assertions passed.

Successful API Response (200 OK):
Screenshot 2026-01-28 194148

Ready for final review and merge.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and response consistency for the users.getPreferences endpoint with standardized error messages for invalid or unauthorized requests.

✏️ Tip: You can customize this high-level summary in your review settings.

@Mohamed-Sobea Mohamed-Sobea requested a review from a team as a code owner January 24, 2026 22:38
@changeset-bot
Copy link

changeset-bot bot commented Jan 24, 2026

🦋 Changeset detected

Latest commit: 5664ef8

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

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

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 24, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 8.3.0, but it targets 7.11.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@CLAassistant
Copy link

CLAassistant commented Jan 24, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

Walkthrough

Reworked the users.getPreferences route to add AJV-based 200/400/401 response validation, moved handler logic into an action returning standardized responses, exported UsersEndpoints type, and augmented @rocket.chat/rest-typings Endpoints.

Changes

Cohort / File(s) Summary
API Users Endpoint Refactoring
apps/meteor/app/api/server/v1/users.ts
Added UserPreferencesResponseSchema and isUserPreferencesResponse AJV validator; declared response map for 200/400/401; replaced inline getPreferences logic with an action() that returns preferences or throws standardized errors; exported UsersEndpoints type and module-augmented @rocket.chat/rest-typings.
Changeset
.changeset/strong-insects-brush.md
New changeset documenting the migration of users.getPreferences to an OpenAPI/AJV response pattern and a patch bump for @rocket.chat/meteor.

Sequence Diagram(s)

(Skipped — changes are localized to a single endpoint and do not introduce a multi-component sequential flow warranting a diagram.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • ggazzo

Poem

🐰 I hopped through schemas, neat and spry,

AJV hummed under moonlit sky,
Responses trimmed and typed just so,
Errors mapped in tidy row,
A rabbit cheers — preferences now fly.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(api): migrate users.getPreferences to OpenAPI pattern' clearly and specifically summarizes the main change: migrating a specific API endpoint to the OpenAPI pattern, which aligns with all the changes in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 1 file

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 2 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.

Please add the swagger docs and remove the users.getPreferences legacy typing code from the rest-typing folder. These are no longer in use and should be purged to avoid confusion.

@ahmed-n-abdeltwab
Copy link
Contributor

ahmed-n-abdeltwab commented Jan 25, 2026

⚠️ Note: Swagger documentation has not yet been added; this PR focuses on migration, validation, and testing. Swagger UI integration can be added in a follow-up PR.

hi @Mohamed-Sobea , Please include the Swagger documentation and clean up the old code in rest-typings so we don't lose track of it across PRs. It’s also a good idea to finish the API in a single PR to keep things clean and concise.

Also I noticed there are a few missing spaces and linting issues that need fixing

@Mohamed-Sobea
Copy link
Author

Hi @ahmed-n-abdeltwab , thank you for the guidance and the detailed feedback! I have implemented the requested changes and consolidated everything into this PR:

Swagger Documentation: I’ve added the response block to the route definition and verified that the documentation is correctly generated at the /api-docs/ route. I've also updated the PR description with a verification screenshot.

Typing Cleanup: I purged the legacy manual definitions from packages/rest-typings as the route now uses ExtractRoutesFromAPI for a single source of truth.

Linting & Formatting: I resolved the spacing issues and other linting errors by running yarn lint -- --fix.

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 2 files

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@apps/meteor/app/api/server/v1/users.ts`:
- Around line 5-7: There is a duplicate import of the symbol "ajv" causing a
TypeScript duplicate identifier error; remove the second/duplicate import so
"ajv" is only imported once (keep the original import line where "ajv" appears
alongside validateBadRequestErrorResponse and validateUnauthorizedErrorResponse
and delete the later redundant import statement or entry that re-exports "ajv"),
then run a build to confirm the compilation error is resolved.
- Around line 875-879: Remove the duplicated UsersEndpoints/type export and
module augmentation added here and instead merge its definitions into the
existing augmentation: delete the new declaration of UsersEndpoints and the
declare module '@rocket.chat/rest-typings' block in this file, then update the
original augmentation (the existing declare module block that defines Endpoints)
to include the additional endpoint routes by combining
ExtractRoutesFromAPI<typeof usersEndpoints> with any other relevant endpoint
types (e.g., ExtractRoutesFromAPI<typeof usersGetPreferencesEndpoint>), and use
the original pattern interface Endpoints extends UsersEndpoints {} (or extend
the combined type via an interface) so the module augmentation remains
consistent and non-duplicative.
- Around line 851-873: The issue is a duplicate const declaration of
usersEndpoints (first used for the users.createToken endpoint and again for
users.getPreferences), so rename the second declaration (e.g.,
usersEndpointsGetPreferences) or refactor to chain the API.v1.get calls into a
single variable instead of redeclaring; then update the exported type/combined
endpoints (the export that currently references usersEndpoints) to include both
endpoint variables or the single chained variable so both users.createToken and
users.getPreferences are included. Ensure you update all references to
usersEndpoints accordingly (including the combined endpoints/type export).

@ahmed-n-abdeltwab
Copy link
Contributor

Hey @Mohamed-Sobea , I noticed CodeRabbit flagged a few items on this PR. I know AI bots can sometimes be hit-or-miss, but it’s usually worth double-checking their logic before dismissing them. If you ever feel like the bot is 'hallucinating' or being too picky, try pushing back! You can actually reply to its comment with something like, 'Are you sure?' or 'Can you explain why this is a problem?' Usually, it will either admit it was wrong or give you a really clear explanation that helps the fix make sense. Could you take these issue?

@ahmed-n-abdeltwab
Copy link
Contributor

ahmed-n-abdeltwab commented Jan 29, 2026

Linting & Formatting: I resolved the spacing issues and other linting errors by running yarn lint -- --fix.

Nice work on the linting! Just wanted to share the workflow I usually use to double-check everything. it might save you some time:

For formatting and fixing issues, I usually run:
yarn eslint:fix
And then a quick yarn lint just to make sure everything passes.

To make sure the logic is actually working, I run the specific API test like this:
yarn testapi -f '[Chat]'
You can check the Mocha CLI documentation here to see how that works.

Finally, I always use ripgrep to make sure the endpoint is registered correctly and the paths match between the frontend and the SDK. I usually run something like this:
API="chat\.getMessage" && rg "api\([^)]*${API}|useEndpoint\([^)]*${API}|sdk\.rest\.\w+\([^)]*${API}" --type ts --type js -n

Or for simplicity, you can just use your editor to search for things like useEndpoint, sdk.rest.get('/v1/chat.getMessage'), or get(api('chat.getMessage')).

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.86%. Comparing base (9e92b49) to head (5664ef8).
⚠️ Report is 180 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38325      +/-   ##
===========================================
- Coverage    70.86%   70.86%   -0.01%     
===========================================
  Files         3160     3160              
  Lines       109775   109775              
  Branches     19709    19715       +6     
===========================================
- Hits         77795    77793       -2     
- Misses       29957    29965       +8     
+ Partials      2023     2017       -6     
Flag Coverage Δ
unit 72.05% <ø> (-0.01%) ⬇️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants