Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-operation-channel-schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/parser": patch
---

Fix schema parsing for messages defined through operation channel references.
2 changes: 2 additions & 0 deletions packages/parser/src/custom-operations/parse-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
42 changes: 42 additions & 0 deletions packages/parser/test/custom-operations/parse-schema-v3.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
});
});
});
9 changes: 9 additions & 0 deletions packages/parser/test/mocks/parse/operation-channel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
channels:
BarChannel:
address: test
messages:
AMessage:
payload:
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0'
schema:
type: object
Loading