Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create rule asyncapi3-channel-no-query-nor-fragment for v3 core ruleset #1051

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
---

chore: create rule `asyncapi3-channel-no-query-nor-fragment` for v3 core ruleset
aeworxet marked this conversation as resolved.
Show resolved Hide resolved
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,
},
],
},
]);
Loading