Skip to content

Commit

Permalink
chore: Create the rule asyncapi3-channel-no-query-nor-fragment for …
Browse files Browse the repository at this point in the history
…the v3 core ruleset
  • Loading branch information
aeworxet committed Aug 10, 2024
1 parent 6794729 commit 22aed2f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 14 deletions.
26 changes: 13 additions & 13 deletions packages/parser/src/ruleset/v2/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion packages/parser/src/ruleset/v3/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[\\?#]',
},
},
},
},
};
Original file line number Diff line number Diff line change
@@ -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,
},
],
},
]);

0 comments on commit 22aed2f

Please sign in to comment.