diff --git a/src/ruleset/v2/functions/channelParameters.ts b/src/ruleset/v2/functions/channelParameters.ts index d9d89b548..6d38e875c 100644 --- a/src/ruleset/v2/functions/channelParameters.ts +++ b/src/ruleset/v2/functions/channelParameters.ts @@ -22,7 +22,15 @@ export const channelParameters = createRulesetFunction<{ parameters: Record 0; + if (hasParameters && (path === null || parameters.length === 0)) { + results.push({ + message: `Channel has parameters defined, but the address is null or does not contain any parameters.`, + path: ctx.path.slice(0, -1), + }); + return results; + } const missingParameters = getMissingProps(parameters, targetVal.parameters); if (missingParameters.length) { diff --git a/test/ruleset/rules/v2/asyncapi2-channel-parameters.spec.ts b/test/ruleset/rules/v2/asyncapi2-channel-parameters.spec.ts index fc70a3bca..a1b1811c2 100644 --- a/test/ruleset/rules/v2/asyncapi2-channel-parameters.spec.ts +++ b/test/ruleset/rules/v2/asyncapi2-channel-parameters.spec.ts @@ -16,6 +16,25 @@ testRule('asyncapi2-channel-parameters', [ errors: [], }, + { + name: 'address has no parameters but parameters are defined', + document: { + asyncapi: '2.0.0', + channels: { + 'users/signedUp': { + parameters: { + test: {}, + }, + }, + }, + }, + errors: [{ + message: 'Channel has parameters defined, but the address is null or does not contain any parameters', + path: ['channels', 'users/signedUp'], + severity: DiagnosticSeverity.Error, + },], + }, + { name: 'channel has not defined definition for one of the parameters', document: {