Skip to content

Commit

Permalink
fix: remove unexpected support for traits at Channel Object level (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya authored Jun 5, 2024
1 parent bbb243d commit 8185bc8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/custom-operations/apply-traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ function applyTraitsToObjectV2(value: Record<string, unknown>) {
const v3TraitPaths = [
// operations
'$.operations.*',
'$.operations.*.channel.*',
'$.operations.*.channel.messages.*',
'$.operations.*.messages.*',
'$.components.operations.*',
'$.components.operations.*.channel.*',
'$.components.operations.*.channel.messages.*',
'$.components.operations.*.messages.*',
// Channels
Expand Down
43 changes: 43 additions & 0 deletions test/validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 8185bc8

Please sign in to comment.