From 9c3ddffa801fc5d52fa53d3b5e19452583d39c48 Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Sat, 10 Aug 2024 08:42:20 +0000 Subject: [PATCH 1/3] chore: Create the rule `asyncapi3-channel-no-query-nor-fragment` for the v3 core ruleset --- packages/parser/src/ruleset/v2/ruleset.ts | 26 +++++----- packages/parser/src/ruleset/v3/ruleset.ts | 15 +++++- ...api3-channel-no-query-nor-fragment.spec.ts | 50 +++++++++++++++++++ 3 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 packages/parser/test/ruleset/rules/v3/asyncapi3-channel-no-query-nor-fragment.spec.ts diff --git a/packages/parser/src/ruleset/v2/ruleset.ts b/packages/parser/src/ruleset/v2/ruleset.ts index 7e80f89f6..f5e0d3274 100644 --- a/packages/parser/src/ruleset/v2/ruleset.ts +++ b/packages/parser/src/ruleset/v2/ruleset.ts @@ -49,19 +49,6 @@ export const v2CoreRuleset = { function: serverVariables, }, }, - 'asyncapi2-channel-no-query-nor-fragment': { - description: 'Channel address should not include query ("?") or fragment ("#") delimiter.', - severity: 'error', - recommended: true, - given: '$.channels', - then: { - field: '@key', - function: pattern, - functionOptions: { - notMatch: '[\\?#]', - }, - }, - }, /** * Channel Object rules @@ -86,6 +73,19 @@ export const v2CoreRuleset = { function: channelServers, }, }, + 'asyncapi2-channel-no-query-nor-fragment': { + description: 'Channel address should not include query ("?") or fragment ("#") delimiter.', + severity: 'error', + recommended: true, + given: '$.channels', + then: { + field: '@key', + function: pattern, + functionOptions: { + notMatch: '[\\?#]', + }, + }, + }, /** * Operation Object rules diff --git a/packages/parser/src/ruleset/v3/ruleset.ts b/packages/parser/src/ruleset/v3/ruleset.ts index 724339e84..62e7ecb51 100644 --- a/packages/parser/src/ruleset/v3/ruleset.ts +++ b/packages/parser/src/ruleset/v3/ruleset.ts @@ -56,6 +56,19 @@ export const v3CoreRuleset = { match: '#\\/servers\\/', // If doesn't match, rule fails. }, }, - } + }, + 'asyncapi3-channel-no-query-nor-fragment': { + description: 'Channel address should not include query ("?") or fragment ("#") delimiter.', + severity: 'error', + recommended: true, + given: '$.channels', + then: { + field: '@key', + function: pattern, + functionOptions: { + notMatch: '[\\?#]', + }, + }, + }, }, }; diff --git a/packages/parser/test/ruleset/rules/v3/asyncapi3-channel-no-query-nor-fragment.spec.ts b/packages/parser/test/ruleset/rules/v3/asyncapi3-channel-no-query-nor-fragment.spec.ts new file mode 100644 index 000000000..f0dd5231f --- /dev/null +++ b/packages/parser/test/ruleset/rules/v3/asyncapi3-channel-no-query-nor-fragment.spec.ts @@ -0,0 +1,50 @@ +import { testRule, DiagnosticSeverity } from '../../tester'; + +testRule('asyncapi3-channel-no-query-nor-fragment', [ + { + name: 'valid case', + document: { + asyncapi: '3.0.0', + channels: { + 'users/{userId}/signedUp': {}, + }, + }, + errors: [], + }, + + { + name: 'channels.{channel} contains a query delimiter', + document: { + asyncapi: '3.0.0', + channels: { + 'users/{userId}/signedUp': {}, + 'users/{userId}/signedOut?byMistake={didFatFingerTheSignOutButton}': {}, + }, + }, + errors: [ + { + message: 'Channel address should not include query ("?") or fragment ("#") delimiter.', + path: ['channels', 'users/{userId}/signedOut?byMistake={didFatFingerTheSignOutButton}'], + severity: DiagnosticSeverity.Error, + }, + ], + }, + + { + name: 'channels.{channel} contains a fragment delimiter', + document: { + asyncapi: '3.0.0', + channels: { + 'users/{userId}/signedUp': {}, + 'users/{userId}/signedOut#onPurpose': {}, + }, + }, + errors: [ + { + message: 'Channel address should not include query ("?") or fragment ("#") delimiter.', + path: ['channels', 'users/{userId}/signedOut#onPurpose'], + severity: DiagnosticSeverity.Error, + }, + ], + }, +]); From 2d939aef3aba74b19cbdb145252adc78fa04e42a Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 6 Sep 2024 07:18:34 +0000 Subject: [PATCH 2/3] add changeset --- .changeset/strong-garlics-think.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strong-garlics-think.md diff --git a/.changeset/strong-garlics-think.md b/.changeset/strong-garlics-think.md new file mode 100644 index 000000000..b5c96ea85 --- /dev/null +++ b/.changeset/strong-garlics-think.md @@ -0,0 +1,5 @@ +--- +"@asyncapi/parser": minor +--- + +chore: create rule `asyncapi3-channel-no-query-nor-fragment` for v3 core ruleset From d96dc4bbd6a3af4ae16a9a5caa270d06d19cf73a Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Tue, 10 Sep 2024 13:14:40 +0000 Subject: [PATCH 3/3] change semantic release type --- .changeset/strong-garlics-think.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/strong-garlics-think.md b/.changeset/strong-garlics-think.md index b5c96ea85..ebfbbb1ee 100644 --- a/.changeset/strong-garlics-think.md +++ b/.changeset/strong-garlics-think.md @@ -2,4 +2,4 @@ "@asyncapi/parser": minor --- -chore: create rule `asyncapi3-channel-no-query-nor-fragment` for v3 core ruleset +feat: create rule `asyncapi3-channel-no-query-nor-fragment` for v3 core ruleset