From ece54625a61efaa298cff2dd894eddd97a198d65 Mon Sep 17 00:00:00 2001 From: firstDemoRepo <180681461+abdu1lah26@users.noreply.github.com> Date: Tue, 15 Sep 2026 19:45:03 +0530 Subject: [PATCH 1/2] fix: parse schemas in operation channels --- .../src/custom-operations/parse-schema.ts | 2 + .../custom-operations/parse-schema-v3.spec.ts | 42 +++++++++++++++++++ .../test/mocks/parse/operation-channel.yaml | 9 ++++ 3 files changed, 53 insertions(+) create mode 100644 packages/parser/test/mocks/parse/operation-channel.yaml diff --git a/packages/parser/src/custom-operations/parse-schema.ts b/packages/parser/src/custom-operations/parse-schema.ts index d33c017b4..a7a2f3c58 100644 --- a/packages/parser/src/custom-operations/parse-schema.ts +++ b/packages/parser/src/custom-operations/parse-schema.ts @@ -29,6 +29,8 @@ const customSchemasPathsV3 = [ '$.components.channels.*.messages.*.payload', '$.components.channels.*.messages.*.headers', // operations + '$.operations.*.channel.messages.*.payload', + '$.operations.*.channel.messages.*.headers', '$.operations.*.messages.*.payload', '$.operations.*.messages.*.headers', '$.components.operations.*.messages.*.payload', diff --git a/packages/parser/test/custom-operations/parse-schema-v3.spec.ts b/packages/parser/test/custom-operations/parse-schema-v3.spec.ts index 12cb24403..44731618e 100644 --- a/packages/parser/test/custom-operations/parse-schema-v3.spec.ts +++ b/packages/parser/test/custom-operations/parse-schema-v3.spec.ts @@ -1,6 +1,7 @@ import { AsyncAPIDocumentV3 } from '../../src/models'; import { Parser } from '../../src/parser'; import { filterLastVersionDiagnostics } from '../utils'; +import type { SchemaParser } from '../../src/schema-parser'; import type { v3 } from '../../src/spec-types'; @@ -253,4 +254,45 @@ describe('custom operations for v3 - parse schemas', function() { type: 'string', }); }); + + it('should parse schema through an external operation channel reference', async function() { + const documentRaw = { + asyncapi: '3.0.0', + info: { + title: 'External operation channel test', + version: '1.0.0', + }, + operations: { + operation: { + action: 'receive', + channel: { + $ref: '../mocks/parse/operation-channel.yaml#/channels/BarChannel', + }, + }, + }, + }; + + const customParser: SchemaParser = { + validate: () => [], + parse: async input => ({ + ...(input.data as any), + 'x-custom-parser': true, + }), + getMimeTypes: () => ['application/vnd.aai.asyncapi;version=2.0.0'], + }; + + parser.registerSchemaParser(customParser); + + const { document } = await parser.parse(documentRaw, { + source: __filename, + }); + + expect( + (document?.json() as any).operations.operation.channel.messages.AMessage + .payload.schema, + ).toEqual({ + type: 'object', + 'x-custom-parser': true, + }); + }); }); diff --git a/packages/parser/test/mocks/parse/operation-channel.yaml b/packages/parser/test/mocks/parse/operation-channel.yaml new file mode 100644 index 000000000..41a5faff6 --- /dev/null +++ b/packages/parser/test/mocks/parse/operation-channel.yaml @@ -0,0 +1,9 @@ +channels: + BarChannel: + address: test + messages: + AMessage: + payload: + schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0' + schema: + type: object From 41b66c3865852e8fa8c50dc1dde0784931f747d2 Mon Sep 17 00:00:00 2001 From: firstDemoRepo <180681461+abdu1lah26@users.noreply.github.com> Date: Tue, 15 Sep 2026 19:59:35 +0530 Subject: [PATCH 2/2] chore: add parser changeset --- .changeset/fix-operation-channel-schema.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-operation-channel-schema.md diff --git a/.changeset/fix-operation-channel-schema.md b/.changeset/fix-operation-channel-schema.md new file mode 100644 index 000000000..fcce000b4 --- /dev/null +++ b/.changeset/fix-operation-channel-schema.md @@ -0,0 +1,5 @@ +--- +"@asyncapi/parser": patch +--- + +Fix schema parsing for messages defined through operation channel references.