-
Notifications
You must be signed in to change notification settings - Fork 13.5k
chore: migrate chat.reportMessage endpoint to new OpenAPI pattern with AJV validation #39230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
alchemycodess
wants to merge
7
commits into
RocketChat:develop
from
alchemycodess:chore/migrate-chat-reportMessage-to-openapi
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6d531c1
chore: migrate chat.reportMessage endpoint to new OpenAPI pattern wit…
alchemycodess f2c43fd
fix: add minLength validation for messageId and description
alchemycodess 4a7717c
fix: resolve merge conflicts and address review feedback
alchemycodess 4c4ed70
fix: apply eslint fixes
alchemycodess a44e004
Revert "fix: apply eslint fixes"
alchemycodess aecf048
fix: apply eslint fixes to migrated files only
alchemycodess ee3537c
Merge remote-tracking branch 'upstream/develop' into chore/migrate-ch…
alchemycodess File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/meteor': minor | ||
| '@rocket.chat/rest-typings': minor | ||
| --- | ||
|
|
||
| Migrated chat.reportMessage endpoint to new OpenAPI pattern with AJV validation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ import { MessageTypes } from '@rocket.chat/message-types'; | |
| import { Messages, Users, Rooms, Subscriptions } from '@rocket.chat/models'; | ||
| import { | ||
| ajv, | ||
| isChatReportMessageProps, | ||
| isChatGetURLPreviewProps, | ||
| isChatUpdateProps, | ||
| isChatGetThreadsListProps, | ||
|
|
@@ -275,6 +274,23 @@ const isChatPinMessageProps = ajv.compile<ChatPinMessage>(ChatPinMessageSchema); | |
|
|
||
| const isChatUnpinMessageProps = ajv.compile<ChatUnpinMessage>(ChatUnpinMessageSchema); | ||
|
|
||
| type ChatReportMessage = { | ||
| messageId: IMessage['_id']; | ||
| description: string; | ||
| }; | ||
|
|
||
| const ChatReportMessageSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| messageId: { type: 'string', minLength: 1 }, | ||
| description: { type: 'string', minLength: 1 }, | ||
| }, | ||
| required: ['messageId', 'description'], | ||
| additionalProperties: false, | ||
| }; | ||
|
|
||
| const isChatReportMessageLocalProps = ajv.compile<ChatReportMessage>(ChatReportMessageSchema); | ||
|
|
||
| const chatEndpoints = API.v1 | ||
| .post( | ||
| 'chat.pinMessage', | ||
|
|
@@ -419,6 +435,30 @@ const chatEndpoints = API.v1 | |
| }); | ||
| }, | ||
| ) | ||
| .post( | ||
| 'chat.reportMessage', | ||
| { | ||
| authRequired: true, | ||
| body: isChatReportMessageLocalProps, | ||
| response: { | ||
| 200: ajv.compile<void>({ | ||
| type: 'object', | ||
| properties: { | ||
| success: { type: 'boolean', enum: [true] }, | ||
| }, | ||
| required: ['success'], | ||
| additionalProperties: false, | ||
| }), | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| const { messageId, description } = this.bodyParams; | ||
| await reportMessage(messageId, description, this.userId); | ||
| return API.v1.success(); | ||
| }, | ||
|
Comment on lines
+452
to
+460
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have removed the old checks for messageId and description because they are now handled by the body schema before entering the action function. That makes sense, nice |
||
| ) | ||
| .post( | ||
| 'chat.starMessage', | ||
| { | ||
|
|
@@ -555,7 +595,6 @@ const chatEndpoints = API.v1 | |
| } | ||
|
|
||
| await unfollowMessage(this.user, { mid }); | ||
|
|
||
| return API.v1.success(); | ||
| }, | ||
| ); | ||
|
|
@@ -677,27 +716,6 @@ API.v1.addRoute( | |
| }, | ||
| ); | ||
|
|
||
| API.v1.addRoute( | ||
| 'chat.reportMessage', | ||
| { authRequired: true, validateParams: isChatReportMessageProps }, | ||
| { | ||
| async post() { | ||
| const { messageId, description } = this.bodyParams; | ||
| if (!messageId) { | ||
| return API.v1.failure('The required "messageId" param is missing.'); | ||
| } | ||
|
|
||
| if (!description) { | ||
| return API.v1.failure('The required "description" param is missing.'); | ||
| } | ||
|
|
||
| await reportMessage(messageId, description, this.userId); | ||
|
|
||
| return API.v1.success(); | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| API.v1.addRoute( | ||
| 'chat.ignoreUser', | ||
| { authRequired: true, validateParams: isChatIgnoreUserProps }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve non-empty validation for
messageIdanddescription.Line 217 and Line 218 allow empty strings, so
{ "messageId": "", "description": "" }passes schema validation. That relaxes input checks during a migration that should keep behavior unchanged.Proposed minimal fix
const ChatReportMessageSchema = { type: 'object', properties: { - messageId: { type: 'string' }, - description: { type: 'string' }, + messageId: { type: 'string', minLength: 1 }, + description: { type: 'string', minLength: 1 }, }, required: ['messageId', 'description'], additionalProperties: false, };Based on learnings: In Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1, avoid introducing logic changes and keep behavior preserved.
📝 Committable suggestion
🤖 Prompt for AI Agents
✅ Addressed in commit f2c43fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 1546
@ahmed-n-abdeltwabActually, addingminLengthvalidation is in scope for this migration! Here's why:The original
reportMessagefunction (which the legacy endpoint called) validates the description:So the legacy endpoint did reject empty descriptions — it just happened later in the call chain rather than at schema validation. Adding
minLength: 1preserves this existing behavior by moving the validation earlier (to the schema layer), which is the correct approach for OpenAPI migrations.Result: Empty strings were already being rejected before your PR, so adding
minLength: 1maintains the original behavior rather than introducing a new restriction. This aligns with keeping the migration scope tight and behavior-preserving. ✅🐰
✏️ Learnings added
🧠 Learnings used