Skip to content

feat: Add OpenAPI Support to chat.getMessage API#36819

Open
ahmed-n-abdeltwab wants to merge 8 commits intoRocketChat:developfrom
ahmed-n-abdeltwab:feat/openapi-chat-getMessage
Open

feat: Add OpenAPI Support to chat.getMessage API#36819
ahmed-n-abdeltwab wants to merge 8 commits intoRocketChat:developfrom
ahmed-n-abdeltwab:feat/openapi-chat-getMessage

Conversation

@ahmed-n-abdeltwab
Copy link
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab commented Aug 28, 2025

Description:
This PR integrates OpenAPI support into the Rocket.Chat API, migrate of Rocket.Chat API endpoints to the new OpenAPI pattern. The update includes improved API documentation, enhanced type safety, and response validation using AJV.

Key Changes:

  • Implemented the new pattern and added AJV-based JSON schema validation for API.
  • Uses the ExtractRoutesFromAPI utility from the TypeScript definitions to dynamically derive the routes from the endpoint specifications.
  • Enabled Swagger UI integration for this API.
  • Route Methods Chaining for the endpoints.
  • This does not introduce any breaking changes to the endpoint logic.

Issue Reference:
Relates to #34983, part of the ongoing OpenAPI integration effort.

Testing:

  • Verified that the API response schemas are correctly documented in Swagger UI.
  • All tests passed without any breaking changes

Endpoints:

Looking forward to your feedback! 🚀

Summary by CodeRabbit

  • New Features

    • Added OpenAPI support for the chat.getMessage endpoint to improve API docs and client tooling.
  • Refactor

    • Modernized chat.getMessage routing and validation while preserving observable request/response behavior.
  • Chores

    • Removed the previously generated public typing for chat.getMessage, reducing the published API surface.
  • Bug Fix

    • Normalize message attachments so attachment metadata consistently uses an array format.

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

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Aug 28, 2025

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.2.0, but it targets 8.1.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Aug 28, 2025

🦋 Changeset detected

Latest commit: 4849442

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/rest-typings Patch
@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 Patch
@rocket.chat/web-ui-registration Patch
@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/ui-client Patch
@rocket.chat/media-calls Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/core-typings Patch
@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

@codecov
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.79%. Comparing base (08b586d) to head (4849442).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36819      +/-   ##
===========================================
+ Coverage    70.74%   70.79%   +0.04%     
===========================================
  Files         3159     3159              
  Lines       109384   109384              
  Branches     19676    19650      -26     
===========================================
+ Hits         77383    77437      +54     
+ Misses       29963    29918      -45     
+ Partials      2038     2029       -9     
Flag Coverage Δ
e2e 60.37% <ø> (+0.09%) ⬆️
e2e-api 48.08% <ø> (+0.07%) ⬆️
unit 71.93% <ø> (+0.02%) ⬆️

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.

@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as ready for review September 8, 2025 12:21
@ahmed-n-abdeltwab ahmed-n-abdeltwab requested review from a team as code owners September 8, 2025 12:21
@ahmed-n-abdeltwab
Copy link
Contributor Author

@cardoso , @ggazzo 👍

@Kaustubh1204
Copy link

Kaustubh1204 commented Jan 22, 2026

Hi @ahmed-n-abdeltwab

Thanks for the detailed OpenAPI migration for chat.getMessage. I reviewed the changes and everything looks solid — the endpoint, AJV validations, and the schema improvements are clear and well-structured.
I noticed the branch has a merge conflict with develop and some lint warnings regarding non-null assertions. If needed, I can help with resolving the merge conflict or testing the endpoint on CE/EE environments to unblock this PR.
Let me know how I can assist to move this forward.

@ahmed-n-abdeltwab
Copy link
Contributor Author

Hi @Kaustubh1204 ,

Thanks for the review! I definitely haven't given up on this one, just been a bit tied up.

If you're still down to help with the merge conflicts and testing on CE/EE, that would be awesome and much appreciated! It would definitely help get this over the finish line.

Also, just for context, I've been using this PR as a guide for the migration track and project docs: RocketChat/Rocket.Chat-Open-API#150 It shows the other APIs I'm working on and how everything is structured.

Let me know if you want to jump in, and thanks again for reaching out!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

Walkthrough

Moves chat.getMessage validation and route into the Meteor app with AJV query validation and OpenAPI-style response schema, removes the corresponding type and endpoint declaration from rest-typings, and normalizes message attachment md to arrays during updateMessage processing.

Changes

Cohort / File(s) Summary
Changeset metadata
.changeset/unlucky-sloths-cough.md
Adds a patch changeset for @rocket.chat/meteor and @rocket.chat/rest-typings, noting OpenAPI support for chat.getMessage.
API route & validation
apps/meteor/app/api/server/v1/chat.ts
Reintroduces/relocates chat.getMessage GET endpoint with ChatGetMessage type, ChatGetMessageSchema, and isChatGetMessageProps AJV validator; handler validates msgId, fetches and normalizes the message, returns { message, success: true } or failure.
Removed typings & endpoint declaration
packages/rest-typings/src/v1/chat.ts
Removes ChatGetMessage type, ChatGetMessageSchema, exported isChatGetMessageProps, and the '/v1/chat.getMessage' entry from ChatEndpoints.
Message normalization
apps/meteor/app/lib/server/functions/updateMessage.ts
Ensures each attachment's md field is normalized to an array (maps attachments to guarantee md is an array of Root), adds import for Root from @rocket.chat/message-parser.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Server
  participant Validator as AJV Validator
  participant DB as Database
  participant Normalizer

  Client->>Server: GET /api/v1/chat.getMessage?msgId=...
  Server->>Validator: validate query (ChatGetMessageSchema)
  alt valid
    Server->>DB: fetch message by msgId and user
    DB-->>Server: message (or null)
    alt message found
      Server->>Normalizer: normalize message (attachments.md -> array)
      Normalizer-->>Server: normalized message
      Server-->>Client: 200 { message, success: true }
    else not found
      Server-->>Client: 404 { success: false, error }
    end
  else invalid
    Server-->>Client: 400 { success: false, error }
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • ggazzo

Poem

🐰 I hopped through code and schema light,
Moved a route by starlit night,
AJV stitched the rules in place,
Attachments neatly found their space,
Now messages hop home just right! 🥕

🚥 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: Add OpenAPI Support to chat.getMessage API' directly and clearly summarizes the main objective of the PR: adding OpenAPI support to the chat.getMessage endpoint.
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 3 files

@ahmed-n-abdeltwab ahmed-n-abdeltwab force-pushed the feat/openapi-chat-getMessage branch from 7e1aff5 to 83634f3 Compare January 25, 2026 17:09
@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as draft January 25, 2026 18:12
Comment on lines 77 to 84
// Ensure attachments have proper md arrays before saving
if (editedMessage.attachments) {
editedMessage.attachments = editedMessage.attachments.map((attachment: MessageAttachment) => ({
...attachment,
md: Array.isArray(attachment.md) ? attachment.md : [],
}));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normalize attachments properties to arrays in updateMessage. Previously, the database would ignore attachments because they didn’t follow the MongoDB schema, leading to data loss.

Fortunately, chat.getMessage was used in a test that encountered this attachment issue; because chat.getMessage is strictly typed, the test failed and alerted us. I suspect this change might fix multiple tests. Any test utilizing message attachments should now be resolved.

@ahmed-n-abdeltwab
Copy link
Contributor Author

ahmed-n-abdeltwab commented Jan 26, 2026

It's impressive how effectively this new pattern detected the bug early. Even though I spent all day yesterday tracing and debugging, I think my next step should be to revisit the old PRs. I should update the straightforward ones and fix the buggy ones before expanding the API further. This is a perfect live demonstration of how much more powerful this pattern is.

I think this pattern has transitioning from 'generating Swagger docs and maintaining a single source of truth API' to 'increasing API toughness and resiliency' or it might be from the start was like that. and Im only now seeing the full extent of its power.

@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as ready for review January 26, 2026 13:14
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: 2

🤖 Fix all issues with AI agents
In `@apps/meteor/app/lib/server/functions/updateMessage.ts`:
- Line 77: Remove the inline implementation comment "// Ensure attachments have
proper md arrays before saving" from
apps/meteor/app/lib/server/functions/updateMessage.ts; locate it inside the
updateMessage function (or the exported update message handler) and delete the
comment, and if the rationale must be preserved move the note to external docs,
a unit test name, or the function's JSDoc rather than leaving an inline comment
in the TS implementation.
- Around line 78-83: The current update in updateMessage.ts assumes
editedMessage.attachments is an array and that attachment.md is an array; change
the logic to first coerce editedMessage.attachments into an array when it's a
single object (e.g., if typeof !== 'undefined' and !Array.isArray) before
mapping, and when mapping each MessageAttachment preserve md by converting
non-array md values into an array (wrap single values) rather than replacing
them with [] — keep existing arrays untouched and ensure the result is always an
array of attachments with md as an array.

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

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

@ggazzo ggazzo added this to the 8.2.0 milestone Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants