Skip to content

Commit

Permalink
Use Spectral pattern function
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya committed Nov 28, 2023
1 parent 40d8e7a commit e17e7cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 53 deletions.
42 changes: 0 additions & 42 deletions src/ruleset/v3/functions/requiredOperationChannelUnambiguity.ts

This file was deleted.

16 changes: 9 additions & 7 deletions src/ruleset/v3/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { AsyncAPIFormats } from '../formats';
import { operationMessagesUnambiguity } from './functions/operationMessagesUnambiguity';
import { requiredOperationChannelUnambiguity } from './functions/requiredOperationChannelUnambiguity';
// import { requiredOperationChannelUnambiguity } from './functions/requiredOperationChannelUnambiguity';
import { pattern } from '@stoplight/spectral-functions';

export const v3CoreRuleset = {
description: 'Core AsyncAPI 3.x.x ruleset.',
Expand All @@ -26,16 +27,17 @@ export const v3CoreRuleset = {
},
},
'asyncapi3-required-operation-channel-unambiguity': {
description: 'Required operation (under root channels) "channel" must reference to a required channel (under root channels).',
message: '{{error}}',
description: 'The "channel" field of an operation under the root "operations" object must always reference a channel under the root "channels" object.',
severity: 'error',
recommended: true,
resolved: false, // We use the JSON pointer to match the channel.
given: [
'$.operations.*',
],
given: '$.operations.*',
then: {
function: requiredOperationChannelUnambiguity,
field: 'channel.$ref',
function: pattern,
functionOptions: {
match: '#\\/channels\\/', // If doesn't match, rule fails.
},
},
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ testRule('asyncapi3-required-operation-channel-unambiguity', [
},
errors: [
{
message: 'The channel field of a required operation should point to a required channel.',
path: ['operations', 'UserSignedUp', 'channel'],
message: 'The "channel" field of an operation under the root "operations" object must always reference a channel under the root "channels" object.',
path: ['operations', 'UserSignedUp', 'channel', '$ref'],
severity: DiagnosticSeverity.Error,
}
],
Expand Down Expand Up @@ -252,8 +252,8 @@ testRule('asyncapi3-required-operation-channel-unambiguity', [
},
errors: [
{
message: 'The channel field of a required operation should point to a required channel.',
path: ['operations', 'UserSignedUp', 'channel'],
message: 'The "channel" field of an operation under the root "operations" object must always reference a channel under the root "channels" object.',
path: ['operations', 'UserSignedUp', 'channel', '$ref'],
severity: DiagnosticSeverity.Error,
}
],
Expand Down

0 comments on commit e17e7cd

Please sign in to comment.