From 0f253b2b84c048f16559df7c4085397630a56e6c Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Fri, 29 May 2026 11:47:08 +0200 Subject: [PATCH] fix: parse payload and headers of messages defined in operation.channel --- .../src/custom-operations/parse-schema.ts | 2 + .../custom-operations/parse-schema-v3.spec.ts | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/packages/parser/src/custom-operations/parse-schema.ts b/packages/parser/src/custom-operations/parse-schema.ts index d33c017b4..177d75b31 100644 --- a/packages/parser/src/custom-operations/parse-schema.ts +++ b/packages/parser/src/custom-operations/parse-schema.ts @@ -31,6 +31,8 @@ const customSchemasPathsV3 = [ // operations '$.operations.*.messages.*.payload', '$.operations.*.messages.*.headers', + '$.operations.*.channel.messages.*.payload', + '$.operations.*.channel.messages.*.headers', '$.components.operations.*.messages.*.payload', '$.components.operations.*.messages.*.headers', // messages 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 c8c3ea87f..3463b14e0 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 { AvroSchemaParser } from '@asyncapi/avro-schema-parser'; import type { v3 } from '../../src/spec-types'; @@ -133,4 +134,61 @@ describe('custom operations for v3 - parse schemas', function() { expect(document).toBeUndefined(); expect(diagnostics.length > 0).toEqual(true); }); + + it('should parse message schemas defined in operation.channel with non-default schema parsers', async function() { + const parserWithAvroSchemaParser = new Parser(); + parserWithAvroSchemaParser.registerSchemaParser(AvroSchemaParser()); + + const documentRaw = { + asyncapi: '3.1.0', + info: { + title: 'Valid AsyncApi document', + version: '1.0.0' + }, + operations: { + operation: { + action: 'send', + channel: { + messages: { + message: { + payload: { + schemaFormat: 'application/vnd.apache.avro;version=1.9.0', + schema: { + type: 'record', + name: 'payload', + fields: [ + { + name: 'payloadField', + type: 'string' + } + ] + } + }, + headers: { + schemaFormat: 'application/vnd.apache.avro;version=1.9.0', + schema: { + type: 'record', + name: 'header', + fields: [ + { + name: 'headerField', + type: 'string' + } + ] + } + } + } + } + } + } + } + }; + const { document, diagnostics } = await parserWithAvroSchemaParser.parse(documentRaw); + + expect(document).toBeInstanceOf(AsyncAPIDocumentV3); + expect(diagnostics.length === 0).toEqual(true); + + expect(((((document?.json() as any).operations?.operation as v3.OperationObject).channel as v3.ChannelObject)?.messages?.message as v3.MessageObject)?.payload?.schema).toEqual({ type: 'object', required: ['payloadField'], properties: { payloadField: { type: 'string' } }, 'x-parser-schema-id': 'payload', }); + expect((((((document?.json() as any).operations?.operation as v3.OperationObject).channel as v3.ChannelObject)?.messages?.message as v3.MessageObject)?.headers as v3.MultiFormatObject)?.schema).toEqual({ type: 'object', required: ['headerField'], properties: { headerField: { type: 'string' } }, 'x-parser-schema-id': 'header', }); + }); });