From e3edd50ff208fb13cc5b1dc0776469942b528056 Mon Sep 17 00:00:00 2001 From: Liam Oldershaw Date: Fri, 11 Jul 2025 11:45:36 +1200 Subject: [PATCH 1/2] Update parse-schema.ts --- packages/parser/src/custom-operations/parse-schema.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/parser/src/custom-operations/parse-schema.ts b/packages/parser/src/custom-operations/parse-schema.ts index d33c017b4..a21b2c8be 100644 --- a/packages/parser/src/custom-operations/parse-schema.ts +++ b/packages/parser/src/custom-operations/parse-schema.ts @@ -31,6 +31,7 @@ const customSchemasPathsV3 = [ // operations '$.operations.*.messages.*.payload', '$.operations.*.messages.*.headers', + '$.operations.*.channel.messages.*.payload', '$.components.operations.*.messages.*.payload', '$.components.operations.*.messages.*.headers', // messages From a87a06a24cdf38b1c6e0acc9003329bd928e1612 Mon Sep 17 00:00:00 2001 From: Liam Oldershaw Date: Tue, 5 Aug 2025 16:50:43 +1200 Subject: [PATCH 2/2] Added unit test to check that a custom parser is triggered on schemas only definined in an operations channel --- .../custom-operations/parse-schema-v3.spec.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) 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 6e56ed10a..952991de5 100644 --- a/packages/parser/test/custom-operations/parse-schema-v3.spec.ts +++ b/packages/parser/test/custom-operations/parse-schema-v3.spec.ts @@ -1,7 +1,9 @@ import { AsyncAPIDocumentV3 } from '../../src/models'; import { Parser } from '../../src/parser'; +import { ValidateSchemaInput, ParseSchemaInput } from '../../src/schema-parser'; import type { v3 } from '../../src/spec-types'; +import { SchemaValidateResult, AsyncAPISchema } from '../../src/types'; describe('custom operations for v3 - parse schemas', function() { const parser = new Parser(); @@ -133,3 +135,53 @@ describe('custom operations for v3 - parse schemas', function() { expect(diagnostics.length > 0).toEqual(true); }); }); + +describe('custom parsers are executed for v3 - parse schemas', function() { + const parser = new Parser(); + parser.registerSchemaParser({ + getMimeTypes (): string[] { + return ['testFormat']; + }, + validate (input: ValidateSchemaInput): void | SchemaValidateResult[] | Promise { + return []; + }, + parse (input: ParseSchemaInput): AsyncAPISchema | Promise { + return {title: 'parsedFormat'}; + } + }); + + it('should parse schemas only defined through an operations channel', async function () { + const documentRaw = { + asyncapi: '3.0.0', + info: { + title: 'Valid AsyncApi document', + version: '1.0' + }, + operations: { + operation: { + action: 'receive', + channel: { + address: 'channel', + messages: { + message: { + payload: { + schemaFormat: 'testFormat', + schema: { + type: 'object' + } + } + } + } + }, + } + }, + }; + + const { document, diagnostics } = await parser.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({ title: 'parsedFormat'}); + }); +}); \ No newline at end of file