Skip to content

Conversation

@ahmed-n-abdeltwab
Copy link
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab commented Apr 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: (processing)

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

Endpoints: (processing)

Looking forward to your feedback! 🚀


This pull request introduces OpenAPI support to the Engagement Dashboard API within the Rocket.Chat repository. The changes focus on enhancing the API's structure and validation processes. Specifically, the TypeScript types for API responses have been refactored by introducing a new helper type, ResultForStatus, to improve maintainability. Additionally, several API endpoints in the Engagement Dashboard's users section have been updated to utilize the API.v1.get method along with ajv for schema validation of request queries and responses. This transition from the older API.v1.addRoute structure ensures more consistent API contract definitions and validation.

@dionisio-bot
Copy link
Contributor

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

🦋 Changeset detected

Latest commit: 32dfe9f

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/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/freeswitch 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/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/federation-service Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service 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/ui-voip 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

@kody-ai
Copy link

kody-ai bot commented Apr 27, 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.

@CLAassistant
Copy link

CLAassistant commented Apr 27, 2025

CLA assistant check
All committers have signed the CLA.

@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as draft April 27, 2025 14:18
@ahmed-n-abdeltwab
Copy link
Contributor Author

📊 Add OpenAPI Support to Engagement Dashboard API

I made this PR a draft because the test results returned 0 passing, 12 pending


✅ Test Results

$ yarn testapi -f 'Engagement Dashboard'    


  [Engagement Dashboard]
    [/engagement-dashboard/channels/list]
      - should fail if user does not have the view-engagement-dashboard permission
      - should fail if start param is not a valid date
      - should fail if end param is not a valid date
      - should fail if start param is not provided
      - should fail if end param is not provided
      - should succesfuly return results
      - should not return empty rooms when the hideRoomsWithNoActivity param is provided
      - should correctly count messages in an empty room
      - should correctly count messages diff compared to last week when the hideRoomsWithNoActivity param is provided and there are messages in a room
      - should correctly count messages diff compared to last week when there are messages in a room
      - should correctly count messages from last week and diff when moving to the next week and providing the hideRoomsWithNoActivity param
      - should correctly count messages from last week and diff when moving to the next week


  0 passing (981ms)
  12 pending

@kody-ai
Copy link

kody-ai bot commented Apr 27, 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.

1 similar comment
@kody-ai
Copy link

kody-ai bot commented Apr 28, 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
Copy link
Contributor Author

ahmed-n-abdeltwab commented Apr 28, 2025

📊 PR Summary

  1. refactor: Rename response schemas for clarity and consistency
  2. fix: Ensure additionalProperties is set to false for error response schemas
  3. fix: Add missing descriptions for error response schemas

✅ Test Results

$ yarn testapi -f 'Engagement Dashboard'    

[Engagement Dashboard]
    [/engagement-dashboard/channels/list]
      - should fail if user does not have the view-engagement-dashboard permission
      - should fail if start param is not a valid date
      - should fail if end param is not a valid date
      - should fail if start param is not provided
      - should fail if end param is not provided
      - should succesfuly return results
      - should not return empty rooms when the hideRoomsWithNoActivity param is provided
      - should correctly count messages in an empty room
      - should correctly count messages diff compared to last week when the hideRoomsWithNoActivity param is provided and there are messages in a room
      - should correctly count messages diff compared to last week when there are messages in a room
      - should correctly count messages from last week and diff when moving to the next week and providing the hideRoomsWithNoActivity param
      - should correctly count messages from last week and diff when moving to the next week


  0 passing (745ms)
  12 pending

GitHub Copilot Review

Your code is well-structured and adheres to TypeScript and API design best practices. However, here are some suggestions for improvement:

1. Error Handling

  • While you have schemas for 400, 401, and 403 responses, consider adding a 500 response schema for unexpected server errors. This will make the API more robust and user-friendly.

2. Code Duplication

  • There is some duplication in the query and response schemas across the .get methods. Consider extracting common schemas (e.g., userActivityQuerySchema, commonBadRequestErrorSchema) into a shared module or variable to reduce redundancy.

3. Type Safety

  • The ajv.compile calls are well-typed, but ensure that the types (IQuery and others) are reused consistently across the codebase to avoid discrepancies.

4. Consistency in API Endpoints

  • Some endpoints start with /v1/engagement-dashboard/users/ while others omit the leading /. Ensure consistency in endpoint definitions.

5. Documentation

  • While the schemas include descriptions, consider adding JSDoc comments for each API endpoint to provide additional context for developers.

6. Performance

  • If the find* functions (e.g., findWeeklyUsersRegisteredData) involve database queries, ensure they are optimized with proper indexing and pagination where applicable.

7. Validation

  • The check function from meteor/check is used for runtime validation. Since you are already using ajv for schema validation, consider consolidating validation logic to avoid redundancy.

8. Logging

  • Add logging for critical operations (e.g., database queries, errors) to help with debugging and monitoring.

9. Security

  • Ensure that sensitive data (e.g., user IDs) is not exposed unnecessarily in the API responses. For example, in the usersList property, consider whether exposing raw user IDs is necessary.

10. Testing

  • Ensure that you have unit and integration tests for all API endpoints to verify their behavior under various scenarios (e.g., valid/invalid inputs, edge cases).

Example Refactor for Common Schemas

You can extract common schemas into a shared variable:

const userCountSchema = {
	type: 'integer',
	description: 'Number of users',
};

const dateSchema = {
	type: 'string',
	format: 'date-time',
	description: 'Date in ISO format',
};

const commonResponseSchema = {
	type: 'object',
	properties: {
		success: { type: 'boolean' },
	},
	required: ['success'],
	additionalProperties: false,
};

Then reuse these schemas in your API definitions.

Final Thoughts

Your code is already in good shape, but implementing these suggestions will improve maintainability, performance, and developer experience. Let me know if you'd like help with specific refactoring!

@kody-ai
Copy link

kody-ai bot commented Apr 28, 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.

@kody-ai
Copy link

kody-ai bot commented Apr 28, 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 ahmed-n-abdeltwab force-pushed the feat/OpenAPI-engagement-dashboard-users branch from fd3725e to dd0c94e Compare July 21, 2025 11:58
@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.

3 participants