-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
ruleset.ts
61 lines (58 loc) · 2.1 KB
/
ruleset.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* eslint-disable sonarjs/no-duplicate-string */
import { AsyncAPIFormats } from '../formats';
import { operationMessagesUnambiguity } from './functions/operationMessagesUnambiguity';
import { pattern } from '@stoplight/spectral-functions';
export const v3CoreRuleset = {
description: 'Core AsyncAPI 3.x.x ruleset.',
formats: AsyncAPIFormats.filterByMajorVersions(['3']).formats(),
rules: {
/**
* Operation Object rules
*/
'asyncapi3-operation-messages-from-referred-channel': {
description: 'Operation "messages" must be a subset of the messages defined in the channel referenced in this operation.',
message: '{{error}}',
severity: 'error',
recommended: true,
resolved: false, // We use the JSON pointer to match the channel.
given: [
'$.operations.*',
'$.components.operations.*',
],
then: {
function: operationMessagesUnambiguity,
},
},
'asyncapi3-required-operation-channel-unambiguity': {
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.*',
then: {
field: 'channel.$ref',
function: pattern,
functionOptions: {
match: '#\\/channels\\/', // If doesn't match, rule fails.
},
},
},
/**
* Channel Object rules
*/
'asyncapi3-required-channel-servers-unambiguity': {
description: 'The "servers" field of a channel under the root "channels" object must always reference a subset of the servers under the root "servers" object.',
severity: 'error',
recommended: true,
resolved: false, // We use the JSON pointer to match the channel.
given: '$.channels.*',
then: {
field: '$.servers.*.$ref',
function: pattern,
functionOptions: {
match: '#\\/servers\\/', // If doesn't match, rule fails.
},
},
}
},
};