From 8185bc8ad748a8ea9752ccf61e99776fd060e123 Mon Sep 17 00:00:00 2001 From: Sergio Moya <1083296+smoya@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:25:19 +0200 Subject: [PATCH] fix: remove unexpected support for traits at Channel Object level (#999) --- src/custom-operations/apply-traits.ts | 2 -- test/validate.spec.ts | 43 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/custom-operations/apply-traits.ts b/src/custom-operations/apply-traits.ts index 6d99453ff..1c2ff7ef0 100644 --- a/src/custom-operations/apply-traits.ts +++ b/src/custom-operations/apply-traits.ts @@ -51,11 +51,9 @@ function applyTraitsToObjectV2(value: Record) { const v3TraitPaths = [ // operations '$.operations.*', - '$.operations.*.channel.*', '$.operations.*.channel.messages.*', '$.operations.*.messages.*', '$.components.operations.*', - '$.components.operations.*.channel.*', '$.components.operations.*.channel.messages.*', '$.components.operations.*.messages.*', // Channels diff --git a/test/validate.spec.ts b/test/validate.spec.ts index 6a3458518..60b85730a 100644 --- a/test/validate.spec.ts +++ b/test/validate.spec.ts @@ -51,4 +51,47 @@ describe('validate()', function() { expect(hasErrorDiagnostic(diagnostics)).toEqual(false); expect(hasWarningDiagnostic(diagnostics)).toEqual(true); }); + + // See https://github.com/asyncapi/parser-js/issues/996 + it('user case - null channel address should not make operation traits appliance fail', async function() { + const documentRaw = { + asyncapi: '3.0.0', + info: { + title: 'Nexus Server API', + version: '1.0.0' + }, + channels: { + Exchange: { + address: null, + messages: { + FooEvent: { + name: 'FooEvent', + title: 'Tenant Created', + contentType: 'application/json', + payload: { + type: 'string' + } + } + } + } + }, + operations: { + sendTenantCreated: { + title: 'Send tenant created event to client', + action: 'send', + channel: { + $ref: '#/channels/Exchange' + }, + messages: [ + { + $ref: '#/channels/Exchange/messages/FooEvent' + } + ] + } + } + }; + const { document, diagnostics } = await parser.parse(documentRaw, { validateOptions: { allowedSeverity: { warning: false } } }); + console.log(diagnostics); + expect(diagnostics).toHaveLength(0); + }); });