-
Notifications
You must be signed in to change notification settings - Fork 13.5k
chore: Add OpenAPI Support to chat.getMessage API #36819
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
base: develop
Are you sure you want to change the base?
Changes from 9 commits
8671a0e
4cc0fcb
7abd6a5
959d685
c65437c
83634f3
1c083d1
4849442
0b34741
3c325d4
ef16af7
765cd11
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": patch | ||
| "@rocket.chat/rest-typings": patch | ||
| --- | ||
|
|
||
| Add OpenAPI support for the Rocket.Chat chat.getMessage 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { AppEvents, Apps } from '@rocket.chat/apps'; | ||
| import { Message } from '@rocket.chat/core-services'; | ||
| import type { IMessage, IUser, AtLeast } from '@rocket.chat/core-typings'; | ||
| import type { Root } from '@rocket.chat/message-parser'; | ||
| import { Messages, Rooms } from '@rocket.chat/models'; | ||
| import { Meteor } from 'meteor/meteor'; | ||
|
|
||
|
|
@@ -76,6 +77,27 @@ export const updateMessage = async function ( | |
| delete editedMessage.md; | ||
| } | ||
|
|
||
| if (editedMessage.attachments != null) { | ||
| const attachments = Array.isArray(editedMessage.attachments) ? editedMessage.attachments : [editedMessage.attachments]; | ||
|
|
||
| editedMessage.attachments = attachments.map((attachment) => { | ||
| let normalizedMd: Root; | ||
|
|
||
| if (Array.isArray(attachment.md)) { | ||
| normalizedMd = attachment.md; | ||
| } else if (attachment.md != null) { | ||
| normalizedMd = [attachment.md]; | ||
| } else { | ||
| normalizedMd = []; | ||
| } | ||
|
|
||
| return { | ||
| ...attachment, | ||
| md: normalizedMd, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
|
Comment on lines
+80
to
+100
Member
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. is this required?
Contributor
Author
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. The short answer is yes. The reason this fixed the problem is that the editedMessage attachments were missing. This caused the test to fail because the JSON schema was able to detect the missing data
Contributor
Author
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. It happens a lot with other APIs too. I'm going to try my best to avoid making any changes, especially to the frontend or the database |
||
| // do not send $unset if not defined. Can cause exceptions in certain mongo versions. | ||
| await Messages.updateOne( | ||
| { _id }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.