Skip to content

chore(api): migrate chat endpoints to OpenAPI#39820

Merged
ggazzo merged 25 commits intochore/apisfrom
chore/apis-2
Mar 24, 2026
Merged

chore(api): migrate chat endpoints to OpenAPI#39820
ggazzo merged 25 commits intochore/apisfrom
chore/apis-2

Conversation

@ggazzo
Copy link
Copy Markdown
Member

@ggazzo ggazzo commented Mar 23, 2026

…ge parameter

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Summary by CodeRabbit

Release Notes

  • New Features

    • Added paginated direct message history endpoint
    • Added paginated direct message list endpoints for retrieving user and public DM rooms
  • Bug Fixes

    • Fixed message pin content handling to prevent undefined values
    • Corrected quote attachment field type definitions for better data consistency
    • Updated validation error formatting for consistency across endpoints
  • Refactor

    • Enhanced chat endpoints with explicit validation schemas and response type definitions

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Mar 23, 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.4.0, but it targets 8.3.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 23, 2026

⚠️ No Changeset found

Latest commit: 5d9b1db

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e7f856d1-7e94-462a-848b-dc25be051073

📥 Commits

Reviewing files that changed from the base of the PR and between 2336ba3 and 5d9b1db.

📒 Files selected for processing (9)
  • apps/meteor/app/api/server/ajv.ts
  • apps/meteor/app/api/server/v1/chat.ts
  • apps/meteor/app/api/server/v1/im.ts
  • apps/meteor/app/autotranslate/client/lib/autotranslate.ts
  • apps/meteor/app/message-pin/server/pinMessage.ts
  • apps/meteor/lib/createQuoteAttachment.ts
  • apps/meteor/tests/end-to-end/api/chat.ts
  • packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts
  • packages/core-typings/src/IMessage/MessageAttachment/MessageQuoteAttachment.ts

Walkthrough

This PR refactors API endpoint definitions for chat and direct message routes to use a fluent builder pattern with explicit OpenAPI/AJV schemas. Additional changes include type refinements for message attachments, conditional field inclusion in quote attachments and pin messages, and test updates reflecting validation error naming conventions.

Changes

Cohort / File(s) Summary
API Schema and Route Refactoring
apps/meteor/app/api/server/ajv.ts, apps/meteor/app/api/server/v1/chat.ts, apps/meteor/app/api/server/v1/im.ts
Migrates standalone API.v1.addRoute calls for chat and DM endpoints into fluent builders (chatEndpoints, dmEndpoints) with explicit OpenAPI/AJV response schemas. Adds runtime schema patching to enforce additionalProperties: false on MessageAttachmentDefault. Introduces new response schemas for paginated message and DM list payloads, and implements validation for the new dm.messages.others/dm.list/dm.list.everyone endpoints.
Message Attachment Type Updates
packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts, packages/core-typings/src/IMessage/MessageAttachment/MessageQuoteAttachment.ts
Extends MessageAttachmentDefault with optional nested attachments array and content object for e2e-encrypted pin preservation. Adjusts MessageQuoteAttachment to make author_link optional and message_link required.
Message Utility Refinements
apps/meteor/app/message-pin/server/pinMessage.ts, apps/meteor/lib/createQuoteAttachment.ts
Conditionally includes optional fields (content, md) in message payloads only when truthy, and simplifies null-check logic using optional chaining in unpinMessage.
Test Error Type Updates
apps/meteor/tests/end-to-end/api/chat.ts
Updates end-to-end assertions for parameter-validation failures to expect errorType as error-invalid-params instead of invalid-params across chat and thread-related endpoints.
Client Code Cleanup
apps/meteor/app/autotranslate/client/lib/autotranslate.ts
Removes TypeScript error-suppression comment from nested attachment translation logic; functional behavior unchanged.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Suggested labels

type: chore


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.

@ggazzo ggazzo force-pushed the chore/apis-2 branch 3 times, most recently from eb144a9 to 9425f11 Compare March 23, 2026 18:36
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.56%. Comparing base (2336ba3) to head (5d9b1db).
⚠️ Report is 1 commits behind head on chore/apis.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff               @@
##           chore/apis   #39820      +/-   ##
==============================================
- Coverage       70.58%   70.56%   -0.02%     
==============================================
  Files            3256     3256              
  Lines          115791   115792       +1     
  Branches        21085    21022      -63     
==============================================
- Hits            81727    81706      -21     
- Misses          31994    32022      +28     
+ Partials         2070     2064       -6     
Flag Coverage Δ
e2e 60.43% <0.00%> (+0.04%) ⬆️
e2e-api 48.12% <ø> (-0.96%) ⬇️
unit 71.10% <0.00%> (-0.03%) ⬇️

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.

This was referenced Mar 23, 2026
ggazzo and others added 13 commits March 23, 2026 20:22
… response schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…response schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…ponse schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…sponse schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…response schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
… response schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…th response schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
… response schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…ponse schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…onse schema

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…to typed endpoints

Converts the last 3 addRoute calls in im.ts (each with dm/im aliases)
to the typed .get() chain pattern with response schemas.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The typed endpoint pattern returns 'error-invalid-params' instead of
'invalid-params' when query/body validation fails.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
POST endpoints using body validators return 'invalid-params' (not
'error-invalid-params'). Only GET endpoints with query validators
use the 'error-' prefix.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
ggazzo and others added 2 commits March 24, 2026 00:00
…t and prevent null md

createQuoteAttachment was propagating null/undefined md from messages.
Now only spreads md when truthy. Also author_link was never set in
createQuoteAttachment so it must be optional in the type.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…te attachments

- Make message_link required in MessageQuoteAttachment (serves as
  discriminator for AJV oneOf)
- Patch MessageAttachmentDefault schema at runtime to add
  additionalProperties: false, preventing it from matching every
  attachment type in the oneOf

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@Harxhit
Copy link
Copy Markdown

Harxhit commented Mar 24, 2026

Sir, @ggazzo @cardoso

Thank your for the update and for working on the mass migration in #39820.

I was following the instructions in RocketChat/Rocket.Chat-Open-API#150
from Ahmed and had claimed the chat endpoints weeks ago. I opened four prs of them (#39603 , #39655, #39669, #39682) that were under review.

To avoid any future conflicts, is there a way I can see which specific endpoints you are currently working on ? That way I can pick different ones and continue contributing without overlapping.

ggazzo and others added 2 commits March 24, 2026 02:11
The pin message attachment includes nested attachments but the type
did not declare it, causing AJV validation to reject it with
additionalProperties: false.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Pin attachments include encrypted content from e2e messages.
Without this field, additionalProperties: false rejects the attachment.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…or attachment translation

Eliminated the @ts-expect-error comments in the AutoTranslate module, clarifying the handling of attachment translations. Updated MessageAttachmentDefault type with a TODO comment to verify the validity of the content field usage.
@ggazzo ggazzo marked this pull request as ready for review March 24, 2026 12:27
@ggazzo ggazzo requested review from a team as code owners March 24, 2026 12:27
@ggazzo ggazzo merged commit c3eb913 into chore/apis Mar 24, 2026
44 of 45 checks passed
@ggazzo ggazzo deleted the chore/apis-2 branch March 24, 2026 12:27
Copy link
Copy Markdown
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.

1 issue found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts">

<violation number="1" location="packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts:40">
P2: `content` is typed too broadly as `object`; use a structured encrypted-content shape to preserve type safety.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

attachments?: MessageAttachment[];

/** Encrypted content from e2e messages, preserved in pin attachments */
content?: object; // TODO: check if MessageAttachmentDefault[content] is a valid type it does not seem to be used anywhere
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 24, 2026

Choose a reason for hiding this comment

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

P2: content is typed too broadly as object; use a structured encrypted-content shape to preserve type safety.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentDefault.ts, line 40:

<comment>`content` is typed too broadly as `object`; use a structured encrypted-content shape to preserve type safety.</comment>

<file context>
@@ -32,4 +33,9 @@ export type MessageAttachmentDefault = {
+	attachments?: MessageAttachment[];
+
+	/** Encrypted content from e2e messages, preserved in pin attachments */
+	content?: object; // TODO: check if MessageAttachmentDefault[content] is a valid type it does not seem to be used anywhere
 } & MessageAttachmentBase;
</file context>
Fix with Cubic

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants