Skip to content

Commit a1e52c9

Browse files
ggazzoclaude
andcommitted
fix(core-typings): fix MessageAttachment oneOf discrimination for quote attachments
- Make message_link required in MessageQuoteAttachment (serves as discriminator for AJV oneOf) - Patch MessageAttachmentDefault schema at runtime to add additionalProperties: false, preventing it from matching every attachment type in the oneOf Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 74eb925 commit a1e52c9

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

apps/meteor/app/api/server/ajv.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { ajv, ajvQuery } from '@rocket.chat/rest-typings';
33

44
const components = schemas.components?.schemas;
55
if (components) {
6+
// Patch MessageAttachmentDefault to reject unknown properties so the oneOf
7+
// discriminator works correctly (otherwise it matches every attachment).
8+
const mad = components.MessageAttachmentDefault;
9+
if (mad && typeof mad === 'object' && 'type' in mad) {
10+
(mad as Record<string, unknown>).additionalProperties = false;
11+
}
12+
613
for (const key in components) {
714
if (Object.prototype.hasOwnProperty.call(components, key)) {
815
const uri = `#/components/schemas/${key}`;

packages/core-typings/src/IMessage/MessageAttachment/MessageQuoteAttachment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type MessageQuoteAttachment = {
77
author_name: string;
88
author_link?: string;
99
author_icon: string;
10-
message_link?: string;
10+
message_link: string;
1111
text: string;
1212
md?: Root;
1313
attachments?: Array<MessageAttachment>; // TODO this is causing issues to define a model, see @ts-expect-error at apps/meteor/app/api/server/v1/channels.ts:274

0 commit comments

Comments
 (0)