chore: Add OpenAPI Support to Statistics API#35692
chore: Add OpenAPI Support to Statistics API#35692ahmed-n-abdeltwab wants to merge 3 commits intoRocketChat:developfrom
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
🦋 Changeset detectedLatest commit: b3f9142 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 |
|
@kody start-review |
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
I usually run 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 --fixThis ensured that only the intended file was fixed and committed correctly. |
|
@kody start-review |
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
@kody start-review |
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
@kody start-review |
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
@kody start-review |
|
Hi @ggazzo, I've refactored the statistics endpoints to improve:
Could you please review these changes and share your feedback. |
ggazzo
left a comment
There was a problem hiding this comment.
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! |
|
@kody start-review |
|
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! |
|
@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 |
Thank you so much. By the way, I looked at it before pinging you, and it passed the statistics test, I saw it. |
|
im going to update this pr |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
ae58c51 to
9539a0a
Compare
|
|
||
| const stats = await Statistics.findLast(); | ||
|
|
||
| if (!stats) { | ||
| return stats; | ||
| } | ||
|
|
||
| // Ensure dates are formatted consistently as strings (same as when refresh=true) | ||
| // This prevents JSON schema validation errors where Date | string types cause ambiguity | ||
| if (stats.migration) { | ||
| stats.migration = { | ||
| ...stats.migration, | ||
| buildAt: formatDate(stats.migration.buildAt), | ||
| lockedAt: formatDate(stats.migration.lockedAt), | ||
| }; | ||
| } | ||
|
|
||
| // Format createdAt if it's a Date object | ||
| if (stats.createdAt instanceof Date) { | ||
| stats.createdAt = stats.createdAt.toString(); | ||
| } | ||
|
|
||
| return stats; |
There was a problem hiding this comment.
The date props coming from the database are causing AJV validation errors because they aren't formatted as strings. As a work around fix, I’ve added a check in this function to ensure the dates passed to the controller are properly formatted. no edit or change was made in the logic
| @@ -27,6 +27,8 @@ import { | |||
| Users, | |||
There was a problem hiding this comment.
In this file, the fix ensures a default value is passed when props are undefined. This aligns with the database interface and prevents unpredictable values from being passed. no edit or change was made in the logic
| federatedUsers: number; | ||
| lastLogin: string; | ||
| lastMessageSentAt: Date | undefined; | ||
| lastMessageSentAt: string | undefined; |
There was a problem hiding this comment.
The use of Date objects should be forbidden due to JSON serialization issues. Additionally, AJV is configured to fail when parsing Date types, as it expects string-formatted timestamps. the right change was made to fix this bug
| onHoldEnabled: boolean; | ||
| emailInboxes: number; | ||
| BusinessHours: { [key: string]: number | string }; | ||
| BusinessHours: { total: number; strategy: string }; |
There was a problem hiding this comment.
Using union types (the OR operator) can be dangerous because Typia interprets them as oneOf. AJV treats oneOf strictly: exactly one schema must match. If both are true or both are false, validation fails. To ensure type safety and predictable behavior, it is recommended to use explicit types. If a developer chooses to use a union type, they must manually handle any potential regressions
|
thanks for the unconcurrency test #38939 i feel like this is going to work |
7a4ded4 to
3b1c650
Compare
…ts by migrating to a modern chained route definition syntax and utilizing shared AJV schemas for validation to enhance API documentation and ensure type safety through response validation.
a9bb7e8 to
e1f7237
Compare
|
The CI is failing because of the /api/v1/autotranslate.translateMessage endpoint. I have migrated it to the new pattern and discovered a bug in it. Both the migration and the bug fix are included in this PR: #38978 |
Description:
This PR integrates OpenAPI support into the
Rocket.Chat API, migrate ofRocket.Chat APIendpoints to the new OpenAPI pattern. The update includes improved API documentation, enhanced type safety, and response validation using AJV.Key Changes:
Issue Reference:
Relates to #34983, part of the ongoing OpenAPI integration effort.
Testing:
Endpoints:
Get Last Statistics
Statistics Telemetry
Looking forward to your feedback! 🚀
Description
This pull request introduces OpenAPI support to the statistics API in the
ahmed-n-abdeltwab/Rocket.Chatrepository. The changes are made in theapps/meteor/app/api/server/v1/stats.tsfile. 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 thefeat/OpenAPIbranch to be merged into thedevelopbranch.