Skip to content

Commit

Permalink
feat: create rule asyncapi3-channel-no-query-nor-fragment for v3 co…
Browse files Browse the repository at this point in the history
…re ruleset (#1051)
  • Loading branch information
aeworxet authored Sep 10, 2024
1 parent 0d33904 commit bebbd39
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-garlics-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/parser": minor
---

feat: create rule `asyncapi3-channel-no-query-nor-fragment` for v3 core ruleset
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 bebbd39

Please sign in to comment.