Skip to content

Conversation

@ahmed-n-abdeltwab
Copy link
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab commented May 27, 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.
  • 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
$ yarn testapi -f '[Users]'

  [Chat]
    /chat.postMessage
      ✔ should throw an error when at least one of required parameters(channel, roomId) is not sent
      ✔ should throw an error when it has some properties with the wrong type(attachments.title_link_download, attachments.fields, message_link) (86ms)
      ✔ should throw an error when the properties (attachments.fields.title, attachments.fields.value) are with the wrong type
      ✔ should return statusCode 200 when postMessage successfully (417ms)
      should throw an error when the sensitive properties contain malicious XSS values
        ✔ attachment.message_link
        ✔ attachment.author_link
        ✔ attachment.title_link
        ✔ attachment.action.url
        ✔ message.avatar
        ✔ attachment.action.image_url
        ✔ attachment.thumb_url
        ✔ attachment.author_icon
        ✔ attachment.image_url
        ✔ attachment.audio_url
        ✔ attachment.video_url
      text message allowed size
        ✔ should return an error if text parameter surpasses the maximum allowed size (50ms)
        ✔ should return an error if text parameter in the first attachment surpasses the maximum allowed size (45ms)
        ✔ should return an error if text parameter in any of the attachments surpasses the maximum allowed size
        ✔ should pass if any text parameter length does not surpasses the maximum allowed size (77ms)
    ***
    ***
    
  168 passing (23s)
  2 pending

Endpoints:

Looking forward to your feedback! 🚀

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented May 27, 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 missing the required milestone or project

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 May 27, 2025

🦋 Changeset detected

Latest commit: d94a574

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

This PR includes changesets to release 42 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/stream-hub-service Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/federation-service Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker 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/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-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/core-typings Patch
@rocket.chat/apps Patch
@rocket.chat/freeswitch 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

@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as ready for review June 3, 2025 13:02
@ahmed-n-abdeltwab ahmed-n-abdeltwab requested review from a team as code owners June 16, 2025 17:10
@ahmed-n-abdeltwab
Copy link
Contributor Author

Hey, @cardoso, the ChatPostMessageEndpoints write now return never, which makes the endpoints act like a base type itself, which makes a problem. So, #36246 needs to be merged first, and then ExtractRoutesFromAPI will not return never, and everything will run like magic, and the CI will not be angry.

export type ChatPostMessageEndpoints = ExtractRoutesFromAPI<typeof chatPostMessageEndpoints>;
// TODO: Need to remove the ChatEndpoints packages/rest-typings/src/index.ts file, but only after implementing all the endpoints.
declare module '@rocket.chat/rest-typings' {
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
interface Endpoints extends ChatPostMessageEndpoints {}
}

@ahmed-n-abdeltwab ahmed-n-abdeltwab force-pushed the feat/openapi-chat-postMessage branch from 372a6e6 to e336a45 Compare June 26, 2025 16:16
@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as draft July 11, 2025 14:11
@codecov
Copy link

codecov bot commented Jul 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.22%. Comparing base (cf51887) to head (d3f4525).
Report is 10 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36090      +/-   ##
===========================================
- Coverage    65.44%   61.22%   -4.23%     
===========================================
  Files         3168     2718     -450     
  Lines       104982    97617    -7365     
  Branches     19991    18248    -1743     
===========================================
- Hits         68709    59769    -8940     
- Misses       33598    35915    +2317     
+ Partials      2675     1933     -742     
Flag Coverage Δ
e2e 41.36% <ø> (-16.82%) ⬇️

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 July 11, 2025 15:10
@ahmed-n-abdeltwab
Copy link
Contributor Author

@cardoso, I think this is going to work now. I tested it locally, and everything looks good.

@ahmed-n-abdeltwab
Copy link
Contributor Author

this pr need an update

@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as draft July 15, 2025 14:14
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 27, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests
  • 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.

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