chore: Add OpenAPI Support to commands.get API#36953
chore: Add OpenAPI Support to commands.get API#36953ggazzo merged 7 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: 31bc752 The changes in this PR will be included in the next version bump. This PR includes changesets to release 40 packages
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 |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe changes introduce OpenAPI support for Rocket.Chat's commands.get API endpoint by migrating the endpoint definition from rest-typings to the main API file, adding type-safe validation through AJV schemas, and extending the public type surface with proper endpoint exports and validators. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
.changeset/wet-roses-call.md (1)
6-6: Clarify scope and cross-reference the tracking issueNit: s/"endpoints"/"endpoint"/ if only commands.get is migrated here, and add "Refs #34983" for traceability.
Apply this diff:
-Add OpenAPI support for the Rocket.Chat commands.get API endpoints 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. +Add OpenAPI support for the Rocket.Chat commands.get API endpoint 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. Refs #34983.apps/meteor/app/api/server/v1/commands.ts (3)
65-65: Type the query paramsCast to
CommandsGetParamsto align with the validated schema and improve editor tooling.Apply this diff:
- const params = this.queryParams; + const params = this.queryParams as CommandsGetParams;
67-69: Redundant runtime check; Ajv already enforces this
query: isCommandsGetParamsrejects missing/non-stringcommandbeforeaction()runs. Drop this branch to avoid conflicting messages with schema errors.Apply this diff:
- if (typeof params.command !== 'string') { - return API.v1.failure('The query param "command" must be provided.'); - }
29-31: Naming nit: singular endpoint constIt holds a single GET route; singular reads clearer and matches usage in the exported type alias.
Apply this diff:
-const commandsEndpoints = API.v1.get( +const commandsGetEndpoint = API.v1.get(and
-export type CommandsEndpoints = ExtractRoutesFromAPI<typeof commandsEndpoints>; +export type CommandsEndpoints = ExtractRoutesFromAPI<typeof commandsGetEndpoint>;Also applies to: 385-386
apps/meteor/tests/end-to-end/api/commands.ts (1)
25-25: Avoid brittle equality on Ajv error textAjv message wording can change across versions. Assert key fragment instead.
Apply this diff:
- expect(res.body.error).to.be.equal(`must have required property 'command'`); + expect(res.body.error).to.include(`required property 'command'`);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
.changeset/wet-roses-call.md(1 hunks)apps/meteor/app/api/server/v1/commands.ts(2 hunks)apps/meteor/tests/end-to-end/api/commands.ts(1 hunks)packages/rest-typings/src/v1/commands.ts(0 hunks)
💤 Files with no reviewable changes (1)
- packages/rest-typings/src/v1/commands.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use descriptive test names that clearly communicate expected behavior
Applied to files:
apps/meteor/tests/end-to-end/api/commands.ts
🧬 Code graph analysis (1)
apps/meteor/app/api/server/v1/commands.ts (2)
packages/rest-typings/src/v1/Ajv.ts (3)
ajv(23-23)validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)packages/rest-typings/src/index.ts (1)
Endpoints(52-100)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #36953 +/- ##
========================================
Coverage 70.55% 70.55%
========================================
Files 3178 3178
Lines 111796 111796
Branches 20134 20188 +54
========================================
+ Hits 78878 78881 +3
+ Misses 30865 30863 -2
+ Partials 2053 2052 -1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/meteor/app/api/server/v1/commands.ts (2)
37-43: Consider using ISlashCommand for type consistency.The generic type parameter uses
SlashCommand(line 38) while the schema referencesISlashCommand(line 43). Although functionally equivalent (ISlashCommand extends SlashCommand), usingISlashCommandconsistently would improve clarity and maintain alignment with the schema reference.Apply this diff for consistency:
- command: SlashCommand; + command: ISlashCommand; success: true; }>({
55-66: Redundant runtime type check after query validation.The
typeof params.command !== 'string'check (line 58) is redundant because theisCommandsGetParamsvalidator (line 33) already ensurescommandis a required string property. If query validation is properly wired in the framework, this condition will never be true.Consider removing the redundant check or adding a comment explaining why it's kept (e.g., defense-in-depth):
async function action() { const params = this.queryParams; - if (typeof params.command !== 'string') { - return API.v1.failure('The query param "command" must be provided.'); - } - const cmd = slashCommands.commands[params.command.toLowerCase()]; if (!cmd) { return API.v1.failure(`There is no command in the system by the name of: ${params.command}`); } return API.v1.success({ command: cmd }); },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
apps/meteor/app/api/server/v1/commands.ts(2 hunks)packages/core-typings/src/Ajv.ts(1 hunks)packages/core-typings/src/SlashCommands/index.ts(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/core-typings/src/SlashCommands/index.ts
🧰 Additional context used
🧬 Code graph analysis (2)
packages/core-typings/src/Ajv.ts (1)
packages/core-typings/src/SlashCommands/index.ts (1)
ISlashCommand(60-60)
apps/meteor/app/api/server/v1/commands.ts (2)
packages/rest-typings/src/v1/Ajv.ts (3)
ajv(23-23)validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)packages/core-typings/src/SlashCommands/index.ts (1)
SlashCommand(46-58)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
🔇 Additional comments (2)
packages/core-typings/src/Ajv.ts (1)
9-14: LGTM! ISlashCommand correctly added to public schemas.The addition of
ISlashCommandto the schemas tuple enables AJV validation for slash command types and makes them available for OpenAPI schema references. This aligns with the PR's OpenAPI integration objectives.apps/meteor/app/api/server/v1/commands.ts (1)
376-381: LGTM! Proper type extraction and module augmentation.The
CommandsEndpointstype correctly extracts routes from the API definition, and the module augmentation properly extends the@rocket.chat/rest-typingsEndpoints interface. This enables type-safe consumption of the new typed route throughout the codebase.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/meteor/app/api/server/v1/commands.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/api/server/v1/commands.ts (3)
packages/rest-typings/src/v1/Ajv.ts (3)
ajv(23-23)validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)packages/core-typings/src/SlashCommands/index.ts (1)
SlashCommand(46-58)packages/rest-typings/src/index.ts (1)
Endpoints(52-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/meteor/app/api/server/v1/commands.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/api/server/v1/commands.ts (3)
packages/rest-typings/src/v1/Ajv.ts (3)
ajv(23-23)validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)packages/core-typings/src/SlashCommands/index.ts (1)
ISlashCommand(60-60)packages/rest-typings/src/index.ts (1)
Endpoints(52-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/meteor/app/api/server/v1/commands.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/api/server/v1/commands.ts (3)
packages/rest-typings/src/v1/Ajv.ts (3)
ajv(23-23)validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)packages/core-typings/src/SlashCommands/index.ts (1)
ISlashCommand(60-60)packages/rest-typings/src/index.ts (1)
Endpoints(52-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
🔇 Additional comments (4)
apps/meteor/app/api/server/v1/commands.ts (4)
1-1: LGTM! Imports correctly support the OpenAPI integration.The imports bring in the necessary types and validation utilities for the typed endpoint pattern.
Also applies to: 4-4, 11-11
16-27: LGTM! Query parameter type and schema are well-defined.The type definition and JSON schema are consistent, and the validation setup follows best practices.
55-73: LGTM! Action function correctly handles command lookup and response construction.The implementation properly:
- Validates command existence with appropriate error handling
- Explicitly constructs the response object with only the intended fields (preventing accidental exposure of non-serializable function fields)
- Uses case-insensitive command lookup
Note: The fields returned here (lines 66-70) should align with the schema definition as flagged in the previous comment.
380-385: LGTM! Type exports and module augmentation correctly expose the new endpoint types.The pattern properly:
- Extracts route types from the API class using
ExtractRoutesFromAPI- Augments
@rocket.chat/rest-typingsto make the new endpoint discoverable- Follows the established convention for typed endpoints
Based on learnings: This aligns with the
@rocket.chat/rest-typingspackage pattern of using declaration merging to extend endpoint typings.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/meteor/app/api/server/v1/commands.ts (1)
16-27: Consider adding minLength constraint to prevent empty command strings.The query validation correctly requires the
commandparameter, but doesn't enforce a minimum length. While the current implementation gracefully handles empty strings (returning a failure at line 72), addingminLength: 1would provide earlier validation feedback.Optional refinement:
const CommandsGetParamsSchema = { type: 'object', properties: { - command: { type: 'string' }, + command: { type: 'string', minLength: 1 }, }, required: ['command'], additionalProperties: false, };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/meteor/app/api/server/v1/commands.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/api/server/v1/commands.ts (3)
packages/rest-typings/src/v1/Ajv.ts (3)
ajv(23-23)validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)packages/core-typings/src/SlashCommands/index.ts (1)
ISlashCommand(60-60)packages/rest-typings/src/index.ts (1)
Endpoints(52-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
🔇 Additional comments (3)
apps/meteor/app/api/server/v1/commands.ts (3)
1-1: LGTM! Clean import additions.The new imports correctly support the OpenAPI integration pattern with proper type imports (
ISlashCommand), validation utilities (ajv, error validators), and route extraction (ExtractRoutesFromAPI).Also applies to: 4-4, 11-11
29-85: Well-structured OpenAPI endpoint with consistent type safety.The implementation successfully migrates to the new OpenAPI pattern:
- Query validation with typed schema (line 33)
- Proper error response schemas (400, 401)
- Inline 200 response schema precisely matches the 5-field TypeScript generic (lines 37-62)
- Response construction (lines 75-83) aligns exactly with the schema definition
- Strict validation via
additionalProperties: false(lines 53, 61)The choice to use an inline schema rather than
$refto fullISlashCommandcorrectly limits the API surface to only the documented 5 fields, as discussed in previous reviews.
391-396: LGTM! Proper type exports and module augmentation.The type export and module augmentation correctly expose the new route definitions to the rest-typings package, enabling type-safe API consumption across the codebase.
0dfd2c0 to
0801d77
Compare
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. - Route Methods Chaining for the endpoints. - This does not introduce any breaking changes to the endpoint logic.
0801d77 to
f99278b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/wet-roses-call.mdapps/meteor/app/api/server/v1/commands.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/meteor/app/api/server/v1/commands.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
🔇 Additional comments (1)
.changeset/wet-roses-call.md (1)
3-3: Thepatchversion bump is appropriate —/v1/commands.getdoes not exist in@rocket.chat/rest-typings.The rest-typings package exports only three command endpoints:
/v1/commands.list,/v1/commands.run, and/v1/commands.preview. The/v1/commands.getendpoint mentioned in the commit title refers to implementation changes in the meteor package, not to changes in rest-typings type definitions. There is no removal of a public endpoint from rest-typings, so thepatchbump is correct.Likely an incorrect or invalid review comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.changeset/wet-roses-call.md:
- Around line 1-4: The changeset currently lists only "@rocket.chat/meteor" and
"@rocket.chat/rest-typings" but you modified files under packages/core-typings
(e.g., src/Ajv.ts), so update .changeset/wet-roses-call.md to include an entry
for "@rocket.chat/core-typings" with an appropriate version bump (patch); ensure
the YAML list includes that package name and "patch" so downstream consumers see
the version change.
There was a problem hiding this comment.
No issues found across 5 files
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
9080d71 to
c0aa2d7
Compare
|
@cardoso 👍 |
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:
Verified that the API response schemas are correctly documented in Swagger UI.
All tests passed without any breaking changes
Endpoints:
Looking forward to your feedback! 🚀
Summary by CodeRabbit
New Features
Refactor
COMM-144