-
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
Changes from 2 commits
6d531c1
f2c43fd
4a7717c
4c4ed70
a44e004
aecf048
ee3537c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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, | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -207,6 +206,23 @@ const isChatPinMessageProps = ajv.compile<ChatPinMessage>(ChatPinMessageSchema); | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const isChatUnpinMessageProps = ajv.compile<ChatUnpinMessage>(ChatUnpinMessageSchema); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| type ChatReportMessage = { | ||||||||||||||||||||||||||||||||||||||
| messageId: string; | ||||||||||||||||||||||||||||||||||||||
| description: string; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const ChatReportMessageSchema = { | ||||||||||||||||||||||||||||||||||||||
| type: 'object', | ||||||||||||||||||||||||||||||||||||||
| properties: { | ||||||||||||||||||||||||||||||||||||||
| messageId: { type: 'string', minLength: 1 }, | ||||||||||||||||||||||||||||||||||||||
| description: { type: 'string', minLength: 1 }, | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| required: ['messageId', 'description'], | ||||||||||||||||||||||||||||||||||||||
| additionalProperties: false, | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+282
to
+290
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. Preserve non-empty validation for Line 217 and Line 218 allow empty strings, so 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
Suggested change
🤖 Prompt for AI Agents✅ Addressed in commit f2c43fd
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. 🧩 Analysis chain🏁 Script executed: Length of output: 1546
The original if (!description.trim()) {
throw new Error('error-invalid-description');
}So the legacy endpoint did reject empty descriptions — it just happened later in the call chain rather than at schema validation. Adding Result: Empty strings were already being rejected before your PR, so adding 🐰 ✏️ Learnings added
🧠 Learnings used |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const isChatReportMessageLocalProps = ajv.compile<ChatReportMessage>(ChatReportMessageSchema); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const chatEndpoints = API.v1 | ||||||||||||||||||||||||||||||||||||||
| .post( | ||||||||||||||||||||||||||||||||||||||
| 'chat.pinMessage', | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -350,6 +366,30 @@ const chatEndpoints = API.v1 | |||||||||||||||||||||||||||||||||||||
| message, | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| .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 |
||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| API.v1.addRoute( | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -513,27 +553,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 }, | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
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 moved the JSON schema, Ajv validation, and interface from rest-typings to chat.ts, but you should also remove the chat.reportMessage related code (the schema, Ajv, and interface) from rest-typings. Since it’s no longer needed there and we are making Meteor the single source of truth for the API, we need to ensure everything is moved to the Meteor file and fully removed from rest-typings to avoid redundancy. |
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.
I think this was IMessage['_id'] in rest-typings. I know it's technically just a string, but we should keep the code consistent with how it was defined in rest-typings