-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathruleset.ts
201 lines (195 loc) · 5.23 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { truthy, schema } from '@stoplight/spectral-functions';
import { documentStructure } from './functions/documentStructure';
import { internal } from './functions/internal';
import { isAsyncAPIDocument } from './functions/isAsyncAPIDocument';
import { unusedComponent } from './functions/unusedComponent';
import { AsyncAPIFormats } from './formats';
import { lastVersion } from '../constants';
export const coreRuleset = {
description: 'Core AsyncAPI x.x.x ruleset.',
formats: AsyncAPIFormats.formats(),
rules: {
/**
* Root Object rules
*/
'asyncapi-is-asyncapi': {
description: 'The input must be a document with a supported version of AsyncAPI.',
formats: [() => true], // run rule for all inputs
message: '{{error}}',
severity: 'error',
recommended: true,
given: '$',
then: {
function: isAsyncAPIDocument,
},
},
'asyncapi-latest-version': {
description: 'Checking if the AsyncAPI document is using the latest version.',
message: `The latest version of AsyncAPi is not used. It is recommended update to the "${lastVersion}" version.`,
recommended: true,
severity: 'info',
given: '$.asyncapi',
then: {
function: schema,
functionOptions: {
schema: {
const: lastVersion,
},
},
},
},
'asyncapi-document-resolved': {
description: 'Checking if the AsyncAPI document has valid resolved structure.',
message: '{{error}}',
severity: 'error',
recommended: true,
given: '$',
then: {
function: documentStructure,
functionOptions: {
resolved: true,
},
},
},
'asyncapi-document-unresolved': {
description: 'Checking if the AsyncAPI document has valid unresolved structure.',
message: '{{error}}',
severity: 'error',
recommended: true,
resolved: false,
given: '$',
then: {
function: documentStructure,
functionOptions: {
resolved: false,
},
},
},
'asyncapi-internal': {
description: 'That rule is internal to extend Spectral functionality for Parser purposes.',
recommended: true,
given: '$',
then: {
function: internal,
},
},
},
};
export const recommendedRuleset = {
description: 'Recommended AsyncAPI x.x.x ruleset.',
formats: AsyncAPIFormats.filterByMajorVersions(['2']).formats(), // Recommended validation for AsyncAPI v3 is still WIP.
rules: {
/**
* Root Object rules
*/
'asyncapi-id': {
description: 'AsyncAPI document should have "id" field.',
recommended: true,
given: '$',
then: {
field: 'id',
function: truthy,
},
},
'asyncapi-defaultContentType': {
description: 'AsyncAPI document should have "defaultContentType" field.',
recommended: true,
given: '$',
then: {
field: 'defaultContentType',
function: truthy,
},
},
/**
* Info Object rules
*/
'asyncapi-info-description': {
description: 'Info "description" should be present and non-empty string.',
recommended: true,
given: '$',
then: {
field: 'info.description',
function: truthy,
},
},
'asyncapi-info-contact': {
description: 'Info object should have "contact" object.',
recommended: true,
given: '$',
then: {
field: 'info.contact',
function: truthy,
},
},
'asyncapi-info-contact-properties': {
description: 'Contact object should have "name", "url" and "email" fields.',
recommended: true,
given: '$.info.contact',
then: [
{
field: 'name',
function: truthy,
},
{
field: 'url',
function: truthy,
},
{
field: 'email',
function: truthy,
},
],
},
'asyncapi-info-license': {
description: 'Info object should have "license" object.',
recommended: true,
given: '$',
then: {
field: 'info.license',
function: truthy,
},
},
'asyncapi-info-license-url': {
description: 'License object should have "url" field.',
recommended: false,
given: '$',
then: {
field: 'info.license.url',
function: truthy,
},
},
/**
* Server Object rules
*/
'asyncapi-servers': {
description: 'AsyncAPI document should have non-empty "servers" object.',
recommended: true,
given: '$',
then: {
field: 'servers',
function: schema,
functionOptions: {
schema: {
type: 'object',
minProperties: 1,
},
allErrors: true,
},
},
},
/**
* Component Object rules
*/
'asyncapi-unused-component': {
description: 'Potentially unused component has been detected in AsyncAPI document.',
formats: AsyncAPIFormats.filterByMajorVersions(['2']).formats(), // Validation for AsyncAPI v3 is still WIP.
recommended: true,
resolved: false,
severity: 'info',
given: '$',
then: {
function: unusedComponent,
},
},
},
};