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 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