Skip to content

Commit 8185bc8

Browse files
authored
fix: remove unexpected support for traits at Channel Object level (#999)
1 parent bbb243d commit 8185bc8

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/custom-operations/apply-traits.ts

-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ function applyTraitsToObjectV2(value: Record<string, unknown>) {
5151
const v3TraitPaths = [
5252
// operations
5353
'$.operations.*',
54-
'$.operations.*.channel.*',
5554
'$.operations.*.channel.messages.*',
5655
'$.operations.*.messages.*',
5756
'$.components.operations.*',
58-
'$.components.operations.*.channel.*',
5957
'$.components.operations.*.channel.messages.*',
6058
'$.components.operations.*.messages.*',
6159
// Channels

test/validate.spec.ts

+43
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,47 @@ describe('validate()', function() {
5151
expect(hasErrorDiagnostic(diagnostics)).toEqual(false);
5252
expect(hasWarningDiagnostic(diagnostics)).toEqual(true);
5353
});
54+
55+
// See https://github.com/asyncapi/parser-js/issues/996
56+
it('user case - null channel address should not make operation traits appliance fail', async function() {
57+
const documentRaw = {
58+
asyncapi: '3.0.0',
59+
info: {
60+
title: 'Nexus Server API',
61+
version: '1.0.0'
62+
},
63+
channels: {
64+
Exchange: {
65+
address: null,
66+
messages: {
67+
FooEvent: {
68+
name: 'FooEvent',
69+
title: 'Tenant Created',
70+
contentType: 'application/json',
71+
payload: {
72+
type: 'string'
73+
}
74+
}
75+
}
76+
}
77+
},
78+
operations: {
79+
sendTenantCreated: {
80+
title: 'Send tenant created event to client',
81+
action: 'send',
82+
channel: {
83+
$ref: '#/channels/Exchange'
84+
},
85+
messages: [
86+
{
87+
$ref: '#/channels/Exchange/messages/FooEvent'
88+
}
89+
]
90+
}
91+
}
92+
};
93+
const { document, diagnostics } = await parser.parse(documentRaw, { validateOptions: { allowedSeverity: { warning: false } } });
94+
console.log(diagnostics);
95+
expect(diagnostics).toHaveLength(0);
96+
});
5497
});

0 commit comments

Comments
 (0)