Skip to content

Conversation

@ahmed-n-abdeltwab
Copy link
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab commented Apr 3, 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 '[Statistics]'


  [Statistics]
    [/statistics]
      ✔ should return an error when the user does not have the necessary permission (248ms)
      ✔ should return an object with the statistics (224ms)
      ✔ should update the statistics when is provided the "refresh:true" query parameter (338ms)
    [/statistics.list]
      ✔ should return an error when the user does not have the necessary permission (273ms)
      ✔ should return an array with the statistics (394ms)
      ✔ should return an array with the statistics even requested with count and offset params (202ms)


  6 passing (2s)

Endpoints:

Looking forward to your feedback! 🚀


Description

This pull request introduces OpenAPI support to the statistics API in the ahmed-n-abdeltwab/Rocket.Chat repository. The changes are made in the apps/meteor/app/api/server/v1/stats.ts file. The update involves refactoring the statistics API routes to incorporate typed validation using ajv schema definitions. This enhancement aims to improve type safety and request validation while preserving the existing functionality of the API. The changes are proposed from the feat/OpenAPI branch to be merged into the develop branch.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Apr 3, 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 Apr 3, 2025

🦋 Changeset detected

Latest commit: 2748afa

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

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

@CLAassistant
Copy link

CLAassistant commented Apr 3, 2025

CLA assistant check
All committers have signed the CLA.

@ahmed-n-abdeltwab ahmed-n-abdeltwab changed the title feat: Add OpenAPI Support to stats api (#34983) feat: Add OpenAPI Support to stats api Apr 3, 2025
@ahmed-n-abdeltwab
Copy link
Contributor Author

@kody start-review

@kody-ai
Copy link

kody-ai bot commented Apr 3, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@ahmed-n-abdeltwab
Copy link
Contributor Author

I usually run yarn lint -- --fix before committing, but this time, after running it, I noticed that it applied fixes across the entire project. As a result, when I added my file to Git and committed, it unintentionally included changes from the entire codebase.

To resolve this, I reverted the unintended changes and manually fixed only my file using the following command:

npx eslint --parser @typescript-eslint/parser --parser-options "project: ['./tsconfig.base.json']" apps/meteor/app/api/server/v1/stats.ts --fix

This ensured that only the intended file was fixed and committed correctly.
Should I report this as an issue, or should we wait to see if it happens again?

@ahmed-n-abdeltwab
Copy link
Contributor Author

@kody start-review

@kody-ai
Copy link

kody-ai bot commented Apr 3, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@ahmed-n-abdeltwab ahmed-n-abdeltwab requested a review from ggazzo April 3, 2025 15:32
@ahmed-n-abdeltwab
Copy link
Contributor Author

@kody start-review

@kody-ai
Copy link

kody-ai bot commented Apr 3, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@ahmed-n-abdeltwab
Copy link
Contributor Author

@kody start-review

@kody-ai
Copy link

kody-ai bot commented Apr 3, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@ggazzo ggazzo modified the milestones: 7.6.0, Short-term Apr 4, 2025
@ggazzo ggazzo self-assigned this Apr 4, 2025
@ahmed-n-abdeltwab
Copy link
Contributor Author

@kody start-review

@ahmed-n-abdeltwab
Copy link
Contributor Author

ahmed-n-abdeltwab commented Apr 4, 2025

Hi @ggazzo,

I've refactored the statistics endpoints to improve:

  1. Code organization (separated handlers from route configs)
  2. Schema validation (additionalProperties: false, added descriptions)
  3. Documentation (OpenAPI compatibility)

Could you please review these changes and share your feedback.

Copy link
Member

@ggazzo ggazzo left a comment

Choose a reason for hiding this comment

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

there is no reason to "over-optimize" the code.

keep the functions and schemas directly in the endpoint declarations.

this way TypeScript can infer things like this, and in this case, since we have several schemas and actions, it is better to understand which one belongs what

@ahmed-n-abdeltwab
Copy link
Contributor Author

there is no reason to "over-optimize" the code.

keep the functions and schemas directly in the endpoint declarations.

this way TypeScript can infer things like this, and in this case, since we have several schemas and actions, it is better to understand which one belongs what

I see your point! My thought was to improve maintainability by keeping things modular, but I can inline them if that's the preferred structure. Let me know if you want any adjustments!

@ahmed-n-abdeltwab ahmed-n-abdeltwab requested a review from ggazzo April 4, 2025 17:18
@ahmed-n-abdeltwab
Copy link
Contributor Author

@kody start-review

@ahmed-n-abdeltwab
Copy link
Contributor Author

ahmed-n-abdeltwab commented Apr 4, 2025

Hey @ggazzo, I’ve made the recent changes you suggested by keeping the functions and schemas inline within the endpoint declarations. I also added types for the query parameters and body, and fixed the schema naming to be uppercase. Let me know if you have any feedback!

@ggazzo
Copy link
Member

ggazzo commented Apr 4, 2025

@ahmed-n-abdeltwab how is your editor configured? we dont need to run the ci to realize we have typescript errors

@ahmed-n-abdeltwab
Copy link
Contributor Author

@ahmed-n-abdeltwab how is your editor configured? we dont need to run the ci to realize we have typescript errors

I'm using Vim as my editor. With default configuration

statistics.routingAlgorithm = settings.get('Livechat_Routing_Method');

// TODO: the onHoldEnabled is duplicated in L205 & L230
// is on-hold active
Copy link
Contributor Author

@ahmed-n-abdeltwab ahmed-n-abdeltwab Jul 10, 2025

Choose a reason for hiding this comment

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

the onHoldEnabled, routingAlgorithm are duplicated in the stats lib

@ahmed-n-abdeltwab
Copy link
Contributor Author

@cardoso, pinging you because I think this PR is ready.

@cardoso
Copy link
Member

cardoso commented Jul 10, 2025

@ahmed-n-abdeltwab seems tests are failing, but could be unrelated, I'll rerun them.

@ahmed-n-abdeltwab
Copy link
Contributor Author

@ahmed-n-abdeltwab seems tests are failing, but could be unrelated, I'll rerun them.

Thank you so much. By the way, I looked at it before pinging you, and it passed the statistics test, I saw it.

@ahmed-n-abdeltwab
Copy link
Contributor Author

im going to update this pr

@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as draft August 5, 2025 06:53
totalFailed: number;
totalPrivateApps: number;
totalPrivateAppsEnabled: number;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Numbers can behave like booleans—0 is treated as false and values greater than 0 as true. This causes confusion with the oneOf schemas generated by Typia

type slashCommandsDataType = { command: string };
type otrDataType = { rid: string };

// TODO this is duplicated from /packages/rest-typings/src/v1/statistics.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

solved

federatedUsers: number;
lastLogin: string;
lastMessageSentAt: Date | undefined;
lastMessageSentAt?: Date;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since both strings and dates are serialized as strings in JSON, Typia's oneOf schema may misinterpret them, leading to validation issues.

@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

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

5 participants