From 0a6d66a71e7b89fc84bd0dc05ccf27ab2ace6108 Mon Sep 17 00:00:00 2001 From: Bishal Date: Tue, 11 Jun 2024 22:22:16 +0000 Subject: [PATCH] added condition to check `parameter` is null or param.length === 0 --- src/ruleset/v2/functions/channelParameters.ts | 10 +++++++++- .../v2/asyncapi2-channel-parameters.spec.ts | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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: {