@redocly/openapi-core 1.0.0-beta.109 → 1.0.0-beta.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/config/config-resolvers.js +21 -3
- package/lib/config/config.d.ts +1 -0
- package/lib/config/config.js +1 -0
- package/lib/config/load.d.ts +8 -2
- package/lib/config/load.js +4 -2
- package/lib/config/types.d.ts +10 -0
- package/lib/config/utils.js +2 -2
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +5 -5
- package/lib/rules/common/assertions/asserts.d.ts +3 -5
- package/lib/rules/common/assertions/asserts.js +137 -97
- package/lib/rules/common/assertions/index.js +2 -6
- package/lib/rules/common/assertions/utils.d.ts +12 -6
- package/lib/rules/common/assertions/utils.js +33 -20
- package/lib/rules/utils.js +1 -1
- package/lib/types/redocly-yaml.js +16 -1
- package/package.json +3 -5
- package/src/__tests__/lint.test.ts +88 -0
- package/src/config/__tests__/config-resolvers.test.ts +37 -1
- package/src/config/__tests__/config.test.ts +5 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +16 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +16 -0
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +11 -0
- package/src/config/__tests__/load.test.ts +1 -1
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/config-resolvers.ts +28 -5
- package/src/config/config.ts +2 -0
- package/src/config/load.ts +10 -4
- package/src/config/types.ts +13 -0
- package/src/config/utils.ts +1 -0
- package/src/rules/ajv.ts +4 -4
- package/src/rules/common/assertions/__tests__/asserts.test.ts +491 -428
- package/src/rules/common/assertions/asserts.ts +155 -97
- package/src/rules/common/assertions/index.ts +2 -11
- package/src/rules/common/assertions/utils.ts +66 -36
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +51 -2
- package/src/rules/utils.ts +2 -1
- package/src/types/redocly-yaml.ts +16 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Location } from '../../../../ref-utils';
|
|
2
2
|
import { Source } from '../../../../resolve';
|
|
3
|
-
import { asserts } from '../asserts';
|
|
3
|
+
import { asserts, buildAssertCustomFunction } from '../asserts';
|
|
4
4
|
|
|
5
5
|
let baseLocation = new Location(jest.fn() as any as Source, 'pointer');
|
|
6
6
|
|
|
@@ -14,61 +14,63 @@ describe('oas3 assertions', () => {
|
|
|
14
14
|
|
|
15
15
|
describe('pattern', () => {
|
|
16
16
|
it('value should match regex pattern', () => {
|
|
17
|
-
expect(asserts.pattern('test string', '/test/', baseLocation)).toEqual(
|
|
18
|
-
expect(asserts.pattern('test string', '/test me/', baseLocation)).toEqual(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
expect(asserts.pattern(['test string', 'test me'], '/test/', baseLocation)).toEqual(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
17
|
+
expect(asserts.pattern('test string', '/test/', baseLocation)).toEqual([]);
|
|
18
|
+
expect(asserts.pattern('test string', '/test me/', baseLocation)).toEqual([
|
|
19
|
+
{ location: baseLocation, message: '"test string" should match a regex /test me/' },
|
|
20
|
+
]);
|
|
21
|
+
expect(asserts.pattern(['test string', 'test me'], '/test/', baseLocation)).toEqual([]);
|
|
22
|
+
expect(asserts.pattern(['test string', 'test me'], '/test me/', baseLocation)).toEqual([
|
|
23
|
+
{
|
|
24
|
+
message: '"test string" should match a regex /test me/',
|
|
25
|
+
location: baseLocation.key(),
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
29
28
|
expect(
|
|
30
29
|
asserts.pattern(
|
|
31
30
|
'./components/smth/test.yaml',
|
|
32
31
|
'/^(./)?components/.*.yaml$/',
|
|
33
32
|
baseLocation
|
|
34
33
|
)
|
|
35
|
-
).toEqual(
|
|
34
|
+
).toEqual([]);
|
|
36
35
|
expect(
|
|
37
36
|
asserts.pattern('./other.yaml', '/^(./)?components/.*.yaml$/', baseLocation)
|
|
38
|
-
).toEqual(
|
|
37
|
+
).toEqual([
|
|
38
|
+
{
|
|
39
|
+
message: '"./other.yaml" should match a regex /^(./)?components/.*.yaml$/',
|
|
40
|
+
location: baseLocation,
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
39
43
|
});
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
describe('ref', () => {
|
|
43
47
|
it('value should have ref', () => {
|
|
44
|
-
expect(asserts.ref({ $ref: 'text' }, true, baseLocation, { $ref: 'text' })).toEqual(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
48
|
+
expect(asserts.ref({ $ref: 'text' }, true, baseLocation, { $ref: 'text' })).toEqual([]);
|
|
49
|
+
expect(asserts.ref({}, true, baseLocation, {})).toEqual([
|
|
50
|
+
{
|
|
51
|
+
message: 'should use $ref',
|
|
52
|
+
location: baseLocation.key(),
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
52
55
|
});
|
|
53
56
|
|
|
54
57
|
it('value should not have ref', () => {
|
|
55
|
-
expect(asserts.ref({ $ref: 'text' }, false, baseLocation, { $ref: 'text' })).toEqual(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
58
|
+
expect(asserts.ref({ $ref: 'text' }, false, baseLocation, { $ref: 'text' })).toEqual([
|
|
59
|
+
{
|
|
60
|
+
message: 'should not use $ref',
|
|
61
|
+
location: baseLocation,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
expect(asserts.ref({}, false, baseLocation, {})).toEqual([]);
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
it('value should match regex pattern', () => {
|
|
66
68
|
expect(
|
|
67
69
|
asserts.ref({ $ref: 'test string' }, '/test/', baseLocation, { $ref: 'test string' })
|
|
68
|
-
).toEqual(
|
|
70
|
+
).toEqual([]);
|
|
69
71
|
expect(
|
|
70
72
|
asserts.ref({ $ref: 'test string' }, '/test me/', baseLocation, { $ref: 'test string' })
|
|
71
|
-
).toEqual({
|
|
73
|
+
).toEqual([{ message: '$ref value should match /test me/', location: baseLocation }]);
|
|
72
74
|
expect(
|
|
73
75
|
asserts.ref(
|
|
74
76
|
{ $ref: './components/smth/test.yaml' },
|
|
@@ -76,7 +78,7 @@ describe('oas3 assertions', () => {
|
|
|
76
78
|
baseLocation,
|
|
77
79
|
{ $ref: './components/smth/test.yaml' }
|
|
78
80
|
)
|
|
79
|
-
).toEqual(
|
|
81
|
+
).toEqual([]);
|
|
80
82
|
expect(
|
|
81
83
|
asserts.ref(
|
|
82
84
|
{ $ref: './paths/smth/test.yaml' },
|
|
@@ -84,420 +86,458 @@ describe('oas3 assertions', () => {
|
|
|
84
86
|
baseLocation,
|
|
85
87
|
{ $ref: './paths/smth/test.yaml' }
|
|
86
88
|
)
|
|
87
|
-
).toEqual(
|
|
89
|
+
).toEqual([
|
|
90
|
+
{
|
|
91
|
+
message: '$ref value should match /^(./)?components/.*.yaml$/',
|
|
92
|
+
location: baseLocation,
|
|
93
|
+
},
|
|
94
|
+
]);
|
|
88
95
|
});
|
|
89
96
|
});
|
|
90
97
|
|
|
91
98
|
describe('enum', () => {
|
|
92
99
|
it('value should be among predefined keys', () => {
|
|
93
|
-
expect(asserts.enum('test', ['test', 'example'], baseLocation)).toEqual(
|
|
94
|
-
expect(asserts.enum(['test'], ['test', 'example'], baseLocation)).toEqual(
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
expect(asserts.enum(['test', 'example'], ['test', 'example'], baseLocation)).toEqual({
|
|
98
|
-
isValid: true,
|
|
99
|
-
});
|
|
100
|
+
expect(asserts.enum('test', ['test', 'example'], baseLocation)).toEqual([]);
|
|
101
|
+
expect(asserts.enum(['test'], ['test', 'example'], baseLocation)).toEqual([]);
|
|
102
|
+
expect(asserts.enum(['test', 'example'], ['test', 'example'], baseLocation)).toEqual([]);
|
|
100
103
|
expect(asserts.enum(['test', 'example', 'foo'], ['test', 'example'], baseLocation)).toEqual(
|
|
101
|
-
|
|
104
|
+
[
|
|
105
|
+
{
|
|
106
|
+
message: '"foo" should be one of the predefined values',
|
|
107
|
+
location: baseLocation.child('foo').key(),
|
|
108
|
+
},
|
|
109
|
+
]
|
|
102
110
|
);
|
|
103
|
-
expect(asserts.enum('test', ['foo', 'example'], baseLocation)).toEqual(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
expect(asserts.enum('test', ['foo', 'example'], baseLocation)).toEqual([
|
|
112
|
+
{
|
|
113
|
+
message: '"test" should be one of the predefined values',
|
|
114
|
+
location: baseLocation,
|
|
115
|
+
},
|
|
116
|
+
]);
|
|
117
|
+
expect(asserts.enum(['test', 'foo'], ['test', 'example'], baseLocation)).toEqual([
|
|
118
|
+
{
|
|
119
|
+
message: '"foo" should be one of the predefined values',
|
|
120
|
+
location: baseLocation.child('foo').key(),
|
|
121
|
+
},
|
|
122
|
+
]);
|
|
111
123
|
});
|
|
112
124
|
});
|
|
113
125
|
|
|
114
126
|
describe('defined', () => {
|
|
115
127
|
it('value should be defined', () => {
|
|
116
|
-
expect(asserts.defined('test', true, baseLocation)).toEqual(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
128
|
+
expect(asserts.defined('test', true, baseLocation)).toEqual([]);
|
|
129
|
+
expect(asserts.defined(undefined, true, baseLocation)).toEqual([
|
|
130
|
+
{
|
|
131
|
+
message: 'Should be defined',
|
|
132
|
+
location: baseLocation,
|
|
133
|
+
},
|
|
134
|
+
]);
|
|
124
135
|
});
|
|
125
136
|
it('value should be undefined', () => {
|
|
126
|
-
expect(asserts.defined(undefined, false, baseLocation)).toEqual(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
137
|
+
expect(asserts.defined(undefined, false, baseLocation)).toEqual([]);
|
|
138
|
+
expect(asserts.defined('test', false, baseLocation)).toEqual([
|
|
139
|
+
{
|
|
140
|
+
message: 'Should be not defined',
|
|
141
|
+
location: baseLocation,
|
|
142
|
+
},
|
|
143
|
+
]);
|
|
134
144
|
});
|
|
135
145
|
});
|
|
136
146
|
|
|
137
147
|
describe('undefined', () => {
|
|
138
148
|
it('value should be undefined', () => {
|
|
139
|
-
expect(asserts.undefined(undefined, true, baseLocation)).toEqual(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
});
|
|
149
|
+
expect(asserts.undefined(undefined, true, baseLocation)).toEqual([]);
|
|
150
|
+
expect(asserts.undefined('test', true, baseLocation)).toEqual([
|
|
151
|
+
{
|
|
152
|
+
message: 'Should not be defined',
|
|
153
|
+
location: baseLocation,
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
147
156
|
});
|
|
148
157
|
it('value should be defined', () => {
|
|
149
|
-
expect(asserts.undefined('test', false, baseLocation)).toEqual(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
158
|
+
expect(asserts.undefined('test', false, baseLocation)).toEqual([]);
|
|
159
|
+
expect(asserts.undefined(undefined, false, baseLocation)).toEqual([
|
|
160
|
+
{
|
|
161
|
+
message: 'Should be defined',
|
|
162
|
+
location: baseLocation,
|
|
163
|
+
},
|
|
164
|
+
]);
|
|
157
165
|
});
|
|
158
166
|
});
|
|
159
167
|
|
|
160
168
|
describe('required', () => {
|
|
161
169
|
it('values should be required', () => {
|
|
162
|
-
expect(asserts.required(['one', 'two', 'three'], ['one', 'two'], baseLocation)).toEqual(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
expect(asserts.required(['one', 'two', 'three'], ['one', 'two'], baseLocation)).toEqual([]);
|
|
171
|
+
expect(asserts.required(['one', 'two'], ['one', 'two', 'three'], baseLocation)).toEqual([
|
|
172
|
+
{
|
|
173
|
+
message: 'three is required',
|
|
174
|
+
location: baseLocation.key(),
|
|
175
|
+
},
|
|
176
|
+
]);
|
|
169
177
|
});
|
|
170
178
|
});
|
|
171
179
|
|
|
172
180
|
describe('nonEmpty', () => {
|
|
173
181
|
it('value should not be empty', () => {
|
|
174
|
-
expect(asserts.nonEmpty('test', true, baseLocation)).toEqual(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
182
|
+
expect(asserts.nonEmpty('test', true, baseLocation)).toEqual([]);
|
|
183
|
+
expect(asserts.nonEmpty('', true, baseLocation)).toEqual([
|
|
184
|
+
{
|
|
185
|
+
message: 'Should not be empty',
|
|
186
|
+
location: baseLocation,
|
|
187
|
+
},
|
|
188
|
+
]);
|
|
189
|
+
expect(asserts.nonEmpty(null, true, baseLocation)).toEqual([
|
|
190
|
+
{
|
|
191
|
+
message: 'Should not be empty',
|
|
192
|
+
location: baseLocation,
|
|
193
|
+
},
|
|
194
|
+
]);
|
|
195
|
+
expect(asserts.nonEmpty(undefined, true, baseLocation)).toEqual([
|
|
196
|
+
{
|
|
197
|
+
message: 'Should not be empty',
|
|
198
|
+
location: baseLocation,
|
|
199
|
+
},
|
|
200
|
+
]);
|
|
190
201
|
});
|
|
191
202
|
it('value should be empty', () => {
|
|
192
|
-
expect(asserts.nonEmpty('', false, baseLocation)).toEqual(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
isValid: true,
|
|
202
|
-
location: baseLocation,
|
|
203
|
-
});
|
|
204
|
-
expect(asserts.nonEmpty('test', false, baseLocation)).toEqual({
|
|
205
|
-
isValid: false,
|
|
206
|
-
location: baseLocation,
|
|
207
|
-
});
|
|
203
|
+
expect(asserts.nonEmpty('', false, baseLocation)).toEqual([]);
|
|
204
|
+
expect(asserts.nonEmpty(null, false, baseLocation)).toEqual([]);
|
|
205
|
+
expect(asserts.nonEmpty(undefined, false, baseLocation)).toEqual([]);
|
|
206
|
+
expect(asserts.nonEmpty('test', false, baseLocation)).toEqual([
|
|
207
|
+
{
|
|
208
|
+
message: 'Should be empty',
|
|
209
|
+
location: baseLocation,
|
|
210
|
+
},
|
|
211
|
+
]);
|
|
208
212
|
});
|
|
209
213
|
});
|
|
210
214
|
|
|
211
215
|
describe('minLength', () => {
|
|
212
216
|
it('value should have less or equal than 5 symbols length', () => {
|
|
213
|
-
expect(asserts.minLength('test', 5, baseLocation)).toEqual(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
expect(asserts.minLength([1, 2, 3, 4, 5
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
});
|
|
217
|
+
expect(asserts.minLength('test', 5, baseLocation)).toEqual([
|
|
218
|
+
{
|
|
219
|
+
message: 'Should have at least 5 characters',
|
|
220
|
+
location: baseLocation,
|
|
221
|
+
},
|
|
222
|
+
]);
|
|
223
|
+
expect(asserts.minLength([1, 2, 3, 4], 5, baseLocation)).toEqual([
|
|
224
|
+
{
|
|
225
|
+
message: 'Should have at least 5 characters',
|
|
226
|
+
location: baseLocation,
|
|
227
|
+
},
|
|
228
|
+
]);
|
|
229
|
+
expect(asserts.minLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual([]);
|
|
230
|
+
expect(asserts.minLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual([]);
|
|
231
|
+
expect(asserts.minLength('example', 5, baseLocation)).toEqual([]);
|
|
232
|
+
expect(asserts.minLength([], 5, baseLocation)).toEqual([
|
|
233
|
+
{
|
|
234
|
+
message: 'Should have at least 5 characters',
|
|
235
|
+
location: baseLocation,
|
|
236
|
+
},
|
|
237
|
+
]);
|
|
238
|
+
expect(asserts.minLength('', 5, baseLocation)).toEqual([
|
|
239
|
+
{
|
|
240
|
+
message: 'Should have at least 5 characters',
|
|
241
|
+
location: baseLocation,
|
|
242
|
+
},
|
|
243
|
+
]);
|
|
241
244
|
});
|
|
242
245
|
});
|
|
243
246
|
|
|
244
247
|
describe('maxLength', () => {
|
|
245
248
|
it('value should have more or equal than 5 symbols length', () => {
|
|
246
|
-
expect(asserts.maxLength('test', 5, baseLocation)).toEqual(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
expect(asserts.maxLength('
|
|
263
|
-
isValid: false,
|
|
264
|
-
location: baseLocation,
|
|
265
|
-
});
|
|
266
|
-
expect(asserts.maxLength([], 5, baseLocation)).toEqual({
|
|
267
|
-
isValid: true,
|
|
268
|
-
location: baseLocation,
|
|
269
|
-
});
|
|
270
|
-
expect(asserts.maxLength('', 5, baseLocation)).toEqual({
|
|
271
|
-
isValid: true,
|
|
272
|
-
location: baseLocation,
|
|
273
|
-
});
|
|
249
|
+
expect(asserts.maxLength('test', 5, baseLocation)).toEqual([]);
|
|
250
|
+
expect(asserts.maxLength([1, 2, 3, 4], 5, baseLocation)).toEqual([]);
|
|
251
|
+
expect(asserts.maxLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual([]);
|
|
252
|
+
expect(asserts.maxLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual([
|
|
253
|
+
{
|
|
254
|
+
message: 'Should have at most 5 characters',
|
|
255
|
+
location: baseLocation,
|
|
256
|
+
},
|
|
257
|
+
]);
|
|
258
|
+
expect(asserts.maxLength('example', 5, baseLocation)).toEqual([
|
|
259
|
+
{
|
|
260
|
+
message: 'Should have at most 5 characters',
|
|
261
|
+
location: baseLocation,
|
|
262
|
+
},
|
|
263
|
+
]);
|
|
264
|
+
expect(asserts.maxLength([], 5, baseLocation)).toEqual([]);
|
|
265
|
+
expect(asserts.maxLength('', 5, baseLocation)).toEqual([]);
|
|
274
266
|
});
|
|
275
267
|
});
|
|
276
268
|
|
|
277
269
|
describe('casing', () => {
|
|
278
270
|
it('value should be camelCase', () => {
|
|
279
|
-
expect(asserts.casing(['testExample', 'fooBar'], 'camelCase', baseLocation)).toEqual(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
expect(asserts.casing('testExample', 'camelCase', baseLocation)).toEqual(
|
|
287
|
-
expect(asserts.casing('TestExample', 'camelCase', baseLocation)).toEqual(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
271
|
+
expect(asserts.casing(['testExample', 'fooBar'], 'camelCase', baseLocation)).toEqual([]);
|
|
272
|
+
expect(asserts.casing(['testExample', 'FooBar'], 'camelCase', baseLocation)).toEqual([
|
|
273
|
+
{
|
|
274
|
+
message: '"FooBar" should use camelCase',
|
|
275
|
+
location: baseLocation.child('FooBar').key(),
|
|
276
|
+
},
|
|
277
|
+
]);
|
|
278
|
+
expect(asserts.casing('testExample', 'camelCase', baseLocation)).toEqual([]);
|
|
279
|
+
expect(asserts.casing('TestExample', 'camelCase', baseLocation)).toEqual([
|
|
280
|
+
{
|
|
281
|
+
message: '"TestExample" should use camelCase',
|
|
282
|
+
location: baseLocation,
|
|
283
|
+
},
|
|
284
|
+
]);
|
|
285
|
+
expect(asserts.casing('test-example', 'camelCase', baseLocation)).toEqual([
|
|
286
|
+
{
|
|
287
|
+
message: '"test-example" should use camelCase',
|
|
288
|
+
location: baseLocation,
|
|
289
|
+
},
|
|
290
|
+
]);
|
|
291
|
+
expect(asserts.casing('test_example', 'camelCase', baseLocation)).toEqual([
|
|
292
|
+
{
|
|
293
|
+
message: '"test_example" should use camelCase',
|
|
294
|
+
location: baseLocation,
|
|
295
|
+
},
|
|
296
|
+
]);
|
|
299
297
|
});
|
|
300
298
|
it('value should be PascalCase', () => {
|
|
301
|
-
expect(asserts.casing('TestExample', 'PascalCase', baseLocation)).toEqual(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
expect(asserts.casing('test-example', 'PascalCase', baseLocation)).toEqual(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
299
|
+
expect(asserts.casing('TestExample', 'PascalCase', baseLocation)).toEqual([]);
|
|
300
|
+
expect(asserts.casing(['TestExample', 'FooBar'], 'PascalCase', baseLocation)).toEqual([]);
|
|
301
|
+
expect(asserts.casing(['TestExample', 'fooBar'], 'PascalCase', baseLocation)).toEqual([
|
|
302
|
+
{
|
|
303
|
+
message: '"fooBar" should use PascalCase',
|
|
304
|
+
location: baseLocation.child('fooBar').key(),
|
|
305
|
+
},
|
|
306
|
+
]);
|
|
307
|
+
expect(asserts.casing('testExample', 'PascalCase', baseLocation)).toEqual([
|
|
308
|
+
{
|
|
309
|
+
message: '"testExample" should use PascalCase',
|
|
310
|
+
location: baseLocation,
|
|
311
|
+
},
|
|
312
|
+
]);
|
|
313
|
+
expect(asserts.casing('test-example', 'PascalCase', baseLocation)).toEqual([
|
|
314
|
+
{
|
|
315
|
+
message: '"test-example" should use PascalCase',
|
|
316
|
+
location: baseLocation,
|
|
317
|
+
},
|
|
318
|
+
]);
|
|
319
|
+
expect(asserts.casing('test_example', 'PascalCase', baseLocation)).toEqual([
|
|
320
|
+
{
|
|
321
|
+
message: '"test_example" should use PascalCase',
|
|
322
|
+
location: baseLocation,
|
|
323
|
+
},
|
|
324
|
+
]);
|
|
323
325
|
});
|
|
324
326
|
it('value should be kebab-case', () => {
|
|
325
|
-
expect(asserts.casing('test-example', 'kebab-case', baseLocation)).toEqual(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
expect(asserts.casing('TestExample', 'kebab-case', baseLocation)).toEqual(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
327
|
+
expect(asserts.casing('test-example', 'kebab-case', baseLocation)).toEqual([]);
|
|
328
|
+
expect(asserts.casing(['test-example', 'foo-bar'], 'kebab-case', baseLocation)).toEqual([]);
|
|
329
|
+
expect(asserts.casing(['test-example', 'foo_bar'], 'kebab-case', baseLocation)).toEqual([
|
|
330
|
+
{
|
|
331
|
+
message: '"foo_bar" should use kebab-case',
|
|
332
|
+
location: baseLocation.child('foo_bar').key(),
|
|
333
|
+
},
|
|
334
|
+
]);
|
|
335
|
+
expect(asserts.casing('testExample', 'kebab-case', baseLocation)).toEqual([
|
|
336
|
+
{
|
|
337
|
+
message: '"testExample" should use kebab-case',
|
|
338
|
+
location: baseLocation,
|
|
339
|
+
},
|
|
340
|
+
]);
|
|
341
|
+
expect(asserts.casing('TestExample', 'kebab-case', baseLocation)).toEqual([
|
|
342
|
+
{
|
|
343
|
+
message: '"TestExample" should use kebab-case',
|
|
344
|
+
location: baseLocation,
|
|
345
|
+
},
|
|
346
|
+
]);
|
|
347
|
+
expect(asserts.casing('test_example', 'kebab-case', baseLocation)).toEqual([
|
|
348
|
+
{
|
|
349
|
+
message: '"test_example" should use kebab-case',
|
|
350
|
+
location: baseLocation,
|
|
351
|
+
},
|
|
352
|
+
]);
|
|
347
353
|
});
|
|
348
354
|
it('value should be snake_case', () => {
|
|
349
|
-
expect(asserts.casing('test_example', 'snake_case', baseLocation)).toEqual(
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
expect(asserts.casing('TestExample', 'snake_case', baseLocation)).toEqual(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
355
|
+
expect(asserts.casing('test_example', 'snake_case', baseLocation)).toEqual([]);
|
|
356
|
+
expect(asserts.casing(['test_example', 'foo_bar'], 'snake_case', baseLocation)).toEqual([]);
|
|
357
|
+
expect(asserts.casing(['test_example', 'foo-bar'], 'snake_case', baseLocation)).toEqual([
|
|
358
|
+
{
|
|
359
|
+
message: '"foo-bar" should use snake_case',
|
|
360
|
+
location: baseLocation.child('foo-bar').key(),
|
|
361
|
+
},
|
|
362
|
+
]);
|
|
363
|
+
expect(asserts.casing('testExample', 'snake_case', baseLocation)).toEqual([
|
|
364
|
+
{
|
|
365
|
+
message: '"testExample" should use snake_case',
|
|
366
|
+
location: baseLocation,
|
|
367
|
+
},
|
|
368
|
+
]);
|
|
369
|
+
expect(asserts.casing('TestExample', 'snake_case', baseLocation)).toEqual([
|
|
370
|
+
{
|
|
371
|
+
message: '"TestExample" should use snake_case',
|
|
372
|
+
location: baseLocation,
|
|
373
|
+
},
|
|
374
|
+
]);
|
|
375
|
+
expect(asserts.casing('test-example', 'snake_case', baseLocation)).toEqual([
|
|
376
|
+
{
|
|
377
|
+
message: '"test-example" should use snake_case',
|
|
378
|
+
location: baseLocation,
|
|
379
|
+
},
|
|
380
|
+
]);
|
|
371
381
|
});
|
|
372
382
|
it('value should be MACRO_CASE', () => {
|
|
373
|
-
expect(asserts.casing('TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
expect(asserts.casing('_TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual(
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
expect(asserts.casing('
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
383
|
+
expect(asserts.casing('TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual([]);
|
|
384
|
+
expect(asserts.casing(['TEST_EXAMPLE', 'FOO_BAR'], 'MACRO_CASE', baseLocation)).toEqual([]);
|
|
385
|
+
expect(asserts.casing(['TEST_EXAMPLE', 'FOO-BAR'], 'MACRO_CASE', baseLocation)).toEqual([
|
|
386
|
+
{
|
|
387
|
+
message: '"FOO-BAR" should use MACRO_CASE',
|
|
388
|
+
location: baseLocation.child('FOO-BAR').key(),
|
|
389
|
+
},
|
|
390
|
+
]);
|
|
391
|
+
expect(asserts.casing('TEST_EXAMPLE_', 'MACRO_CASE', baseLocation)).toEqual([
|
|
392
|
+
{
|
|
393
|
+
message: '"TEST_EXAMPLE_" should use MACRO_CASE',
|
|
394
|
+
location: baseLocation,
|
|
395
|
+
},
|
|
396
|
+
]);
|
|
397
|
+
expect(asserts.casing('_TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual([
|
|
398
|
+
{
|
|
399
|
+
message: '"_TEST_EXAMPLE" should use MACRO_CASE',
|
|
400
|
+
location: baseLocation,
|
|
401
|
+
},
|
|
402
|
+
]);
|
|
403
|
+
expect(asserts.casing('TEST__EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual([
|
|
404
|
+
{
|
|
405
|
+
message: '"TEST__EXAMPLE" should use MACRO_CASE',
|
|
406
|
+
location: baseLocation,
|
|
407
|
+
},
|
|
408
|
+
]);
|
|
409
|
+
expect(asserts.casing('TEST-EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual([
|
|
410
|
+
{
|
|
411
|
+
message: '"TEST-EXAMPLE" should use MACRO_CASE',
|
|
412
|
+
location: baseLocation,
|
|
413
|
+
},
|
|
414
|
+
]);
|
|
415
|
+
expect(asserts.casing('testExample', 'MACRO_CASE', baseLocation)).toEqual([
|
|
416
|
+
{
|
|
417
|
+
message: '"testExample" should use MACRO_CASE',
|
|
418
|
+
location: baseLocation,
|
|
419
|
+
},
|
|
420
|
+
]);
|
|
421
|
+
expect(asserts.casing('TestExample', 'MACRO_CASE', baseLocation)).toEqual([
|
|
422
|
+
{
|
|
423
|
+
message: '"TestExample" should use MACRO_CASE',
|
|
424
|
+
location: baseLocation,
|
|
425
|
+
},
|
|
426
|
+
]);
|
|
427
|
+
expect(asserts.casing('test-example', 'MACRO_CASE', baseLocation)).toEqual([
|
|
428
|
+
{
|
|
429
|
+
message: '"test-example" should use MACRO_CASE',
|
|
430
|
+
location: baseLocation,
|
|
431
|
+
},
|
|
432
|
+
]);
|
|
411
433
|
});
|
|
412
434
|
it('value should be COBOL-CASE', () => {
|
|
413
|
-
expect(asserts.casing('TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
expect(asserts.casing('0TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
expect(asserts.casing('
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
expect(asserts.casing('
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
435
|
+
expect(asserts.casing('TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual([]);
|
|
436
|
+
expect(asserts.casing(['TEST-EXAMPLE', 'FOO-BAR'], 'COBOL-CASE', baseLocation)).toEqual([]);
|
|
437
|
+
expect(asserts.casing(['TEST-EXAMPLE', 'FOO_BAR'], 'COBOL-CASE', baseLocation)).toEqual([
|
|
438
|
+
{
|
|
439
|
+
message: '"FOO_BAR" should use COBOL-CASE',
|
|
440
|
+
location: baseLocation.child('FOO_BAR').key(),
|
|
441
|
+
},
|
|
442
|
+
]);
|
|
443
|
+
expect(asserts.casing('TEST-EXAMPLE-', 'COBOL-CASE', baseLocation)).toEqual([
|
|
444
|
+
{
|
|
445
|
+
message: '"TEST-EXAMPLE-" should use COBOL-CASE',
|
|
446
|
+
location: baseLocation,
|
|
447
|
+
},
|
|
448
|
+
]);
|
|
449
|
+
expect(asserts.casing('0TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual([
|
|
450
|
+
{
|
|
451
|
+
message: '"0TEST-EXAMPLE" should use COBOL-CASE',
|
|
452
|
+
location: baseLocation,
|
|
453
|
+
},
|
|
454
|
+
]);
|
|
455
|
+
expect(asserts.casing('-TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual([
|
|
456
|
+
{
|
|
457
|
+
message: '"-TEST-EXAMPLE" should use COBOL-CASE',
|
|
458
|
+
location: baseLocation,
|
|
459
|
+
},
|
|
460
|
+
]);
|
|
461
|
+
expect(asserts.casing('TEST--EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual([
|
|
462
|
+
{
|
|
463
|
+
message: '"TEST--EXAMPLE" should use COBOL-CASE',
|
|
464
|
+
location: baseLocation,
|
|
465
|
+
},
|
|
466
|
+
]);
|
|
467
|
+
expect(asserts.casing('TEST_EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual([
|
|
468
|
+
{
|
|
469
|
+
message: '"TEST_EXAMPLE" should use COBOL-CASE',
|
|
470
|
+
location: baseLocation,
|
|
471
|
+
},
|
|
472
|
+
]);
|
|
473
|
+
expect(asserts.casing('testExample', 'COBOL-CASE', baseLocation)).toEqual([
|
|
474
|
+
{
|
|
475
|
+
message: '"testExample" should use COBOL-CASE',
|
|
476
|
+
location: baseLocation,
|
|
477
|
+
},
|
|
478
|
+
]);
|
|
479
|
+
expect(asserts.casing('TestExample', 'COBOL-CASE', baseLocation)).toEqual([
|
|
480
|
+
{
|
|
481
|
+
message: '"TestExample" should use COBOL-CASE',
|
|
482
|
+
location: baseLocation,
|
|
483
|
+
},
|
|
484
|
+
]);
|
|
485
|
+
expect(asserts.casing('test-example', 'COBOL-CASE', baseLocation)).toEqual([
|
|
486
|
+
{
|
|
487
|
+
message: '"test-example" should use COBOL-CASE',
|
|
488
|
+
location: baseLocation,
|
|
489
|
+
},
|
|
490
|
+
]);
|
|
455
491
|
});
|
|
456
492
|
it('value should be flatcase', () => {
|
|
457
|
-
expect(asserts.casing('testexample', 'flatcase', baseLocation)).toEqual(
|
|
458
|
-
expect(asserts.casing(['testexample', 'foobar'], 'flatcase', baseLocation)).toEqual(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
expect(asserts.casing('testexample_', 'flatcase', baseLocation)).toEqual(
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
expect(asserts.casing('
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
493
|
+
expect(asserts.casing('testexample', 'flatcase', baseLocation)).toEqual([]);
|
|
494
|
+
expect(asserts.casing(['testexample', 'foobar'], 'flatcase', baseLocation)).toEqual([]);
|
|
495
|
+
expect(asserts.casing(['testexample', 'foo_bar'], 'flatcase', baseLocation)).toEqual([
|
|
496
|
+
{
|
|
497
|
+
message: '"foo_bar" should use flatcase',
|
|
498
|
+
location: baseLocation.child('foo_bar').key(),
|
|
499
|
+
},
|
|
500
|
+
]);
|
|
501
|
+
expect(asserts.casing('testexample_', 'flatcase', baseLocation)).toEqual([
|
|
502
|
+
{
|
|
503
|
+
message: '"testexample_" should use flatcase',
|
|
504
|
+
location: baseLocation,
|
|
505
|
+
},
|
|
506
|
+
]);
|
|
507
|
+
expect(asserts.casing('0testexample', 'flatcase', baseLocation)).toEqual([
|
|
508
|
+
{
|
|
509
|
+
message: '"0testexample" should use flatcase',
|
|
510
|
+
location: baseLocation,
|
|
511
|
+
},
|
|
512
|
+
]);
|
|
513
|
+
expect(asserts.casing('testExample', 'flatcase', baseLocation)).toEqual([
|
|
514
|
+
{
|
|
515
|
+
message: '"testExample" should use flatcase',
|
|
516
|
+
location: baseLocation,
|
|
517
|
+
},
|
|
518
|
+
]);
|
|
519
|
+
expect(asserts.casing('TestExample', 'flatcase', baseLocation)).toEqual([
|
|
520
|
+
{
|
|
521
|
+
message: '"TestExample" should use flatcase',
|
|
522
|
+
location: baseLocation,
|
|
523
|
+
},
|
|
524
|
+
]);
|
|
525
|
+
expect(asserts.casing('test-example', 'flatcase', baseLocation)).toEqual([
|
|
526
|
+
{
|
|
527
|
+
message: '"test-example" should use flatcase',
|
|
528
|
+
location: baseLocation,
|
|
529
|
+
},
|
|
530
|
+
]);
|
|
485
531
|
});
|
|
486
532
|
});
|
|
487
533
|
|
|
488
534
|
describe.skip('sortOrder', () => {
|
|
489
535
|
it('value should be ordered in ASC direction', () => {
|
|
490
|
-
expect(asserts.sortOrder(['example', 'foo', 'test'], 'asc', baseLocation)).toEqual(
|
|
491
|
-
isValid: true,
|
|
492
|
-
location: baseLocation,
|
|
493
|
-
});
|
|
536
|
+
expect(asserts.sortOrder(['example', 'foo', 'test'], 'asc', baseLocation)).toEqual([]);
|
|
494
537
|
expect(
|
|
495
538
|
asserts.sortOrder(['example', 'foo', 'test'], { direction: 'asc' }, baseLocation)
|
|
496
|
-
).toEqual(
|
|
497
|
-
expect(asserts.sortOrder(['example'], 'asc', baseLocation)).toEqual(
|
|
498
|
-
isValid: true,
|
|
499
|
-
location: baseLocation,
|
|
500
|
-
});
|
|
539
|
+
).toEqual([]);
|
|
540
|
+
expect(asserts.sortOrder(['example'], 'asc', baseLocation)).toEqual([]);
|
|
501
541
|
expect(asserts.sortOrder(['example', 'test', 'foo'], 'asc', baseLocation)).toEqual({
|
|
502
542
|
isValid: false,
|
|
503
543
|
location: baseLocation,
|
|
@@ -512,7 +552,7 @@ describe('oas3 assertions', () => {
|
|
|
512
552
|
{ direction: 'asc', property: 'name' },
|
|
513
553
|
baseLocation
|
|
514
554
|
)
|
|
515
|
-
).toEqual(
|
|
555
|
+
).toEqual([]);
|
|
516
556
|
expect(
|
|
517
557
|
asserts.sortOrder(
|
|
518
558
|
[{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }],
|
|
@@ -522,17 +562,11 @@ describe('oas3 assertions', () => {
|
|
|
522
562
|
).toEqual({ isValid: false, location: baseLocation });
|
|
523
563
|
});
|
|
524
564
|
it('value should be ordered in DESC direction', () => {
|
|
525
|
-
expect(asserts.sortOrder(['test', 'foo', 'example'], 'desc', baseLocation)).toEqual(
|
|
526
|
-
isValid: true,
|
|
527
|
-
location: baseLocation,
|
|
528
|
-
});
|
|
565
|
+
expect(asserts.sortOrder(['test', 'foo', 'example'], 'desc', baseLocation)).toEqual([]);
|
|
529
566
|
expect(
|
|
530
567
|
asserts.sortOrder(['test', 'foo', 'example'], { direction: 'desc' }, baseLocation)
|
|
531
|
-
).toEqual(
|
|
532
|
-
expect(asserts.sortOrder(['example'], 'desc', baseLocation)).toEqual(
|
|
533
|
-
isValid: true,
|
|
534
|
-
location: baseLocation,
|
|
535
|
-
});
|
|
568
|
+
).toEqual([]);
|
|
569
|
+
expect(asserts.sortOrder(['example'], 'desc', baseLocation)).toEqual([]);
|
|
536
570
|
expect(asserts.sortOrder(['example', 'test', 'foo'], 'desc', baseLocation)).toEqual({
|
|
537
571
|
isValid: false,
|
|
538
572
|
location: baseLocation,
|
|
@@ -547,7 +581,7 @@ describe('oas3 assertions', () => {
|
|
|
547
581
|
{ direction: 'desc', property: 'name' },
|
|
548
582
|
baseLocation
|
|
549
583
|
)
|
|
550
|
-
).toEqual(
|
|
584
|
+
).toEqual([]);
|
|
551
585
|
expect(
|
|
552
586
|
asserts.sortOrder(
|
|
553
587
|
[{ name: 'foo' }, { name: 'baz' }, { name: 'bar' }],
|
|
@@ -562,17 +596,21 @@ describe('oas3 assertions', () => {
|
|
|
562
596
|
it('node should not have more than one property from predefined list', () => {
|
|
563
597
|
expect(
|
|
564
598
|
asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'test'], baseLocation)
|
|
565
|
-
).toEqual(
|
|
566
|
-
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), [], baseLocation)).toEqual(
|
|
567
|
-
isValid: true,
|
|
568
|
-
location: baseLocation.key(),
|
|
569
|
-
});
|
|
599
|
+
).toEqual([]);
|
|
600
|
+
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), [], baseLocation)).toEqual([]);
|
|
570
601
|
expect(
|
|
571
602
|
asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)
|
|
572
|
-
).toEqual(
|
|
603
|
+
).toEqual([
|
|
604
|
+
{ message: 'foo, bar keys should be mutually exclusive', location: baseLocation.key() },
|
|
605
|
+
]);
|
|
573
606
|
expect(
|
|
574
607
|
asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)
|
|
575
|
-
).toEqual(
|
|
608
|
+
).toEqual([
|
|
609
|
+
{
|
|
610
|
+
message: 'foo, bar, test keys should be mutually exclusive',
|
|
611
|
+
location: baseLocation.key(),
|
|
612
|
+
},
|
|
613
|
+
]);
|
|
576
614
|
});
|
|
577
615
|
});
|
|
578
616
|
|
|
@@ -580,48 +618,73 @@ describe('oas3 assertions', () => {
|
|
|
580
618
|
it('node should have all the properties from predefined list', () => {
|
|
581
619
|
expect(
|
|
582
620
|
asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)
|
|
583
|
-
).toEqual(
|
|
621
|
+
).toEqual([]);
|
|
584
622
|
expect(
|
|
585
623
|
asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'baz'], baseLocation)
|
|
586
|
-
).toEqual(
|
|
587
|
-
expect(asserts.mutuallyRequired(Object.keys(fakeNode), [], baseLocation)).toEqual(
|
|
588
|
-
isValid: true,
|
|
589
|
-
location: baseLocation.key(),
|
|
590
|
-
});
|
|
624
|
+
).toEqual([]);
|
|
625
|
+
expect(asserts.mutuallyRequired(Object.keys(fakeNode), [], baseLocation)).toEqual([]);
|
|
591
626
|
expect(
|
|
592
627
|
asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'test'], baseLocation)
|
|
593
|
-
).toEqual(
|
|
628
|
+
).toEqual([
|
|
629
|
+
{ message: 'Properties foo, test are mutually required', location: baseLocation.key() },
|
|
630
|
+
]);
|
|
594
631
|
expect(
|
|
595
632
|
asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)
|
|
596
|
-
).toEqual(
|
|
633
|
+
).toEqual([
|
|
634
|
+
{
|
|
635
|
+
message: 'Properties foo, bar, test are mutually required',
|
|
636
|
+
location: baseLocation.key(),
|
|
637
|
+
},
|
|
638
|
+
]);
|
|
597
639
|
});
|
|
598
640
|
});
|
|
599
641
|
|
|
600
642
|
describe('requireAny', () => {
|
|
601
643
|
it('node must have at least one property from predefined list', () => {
|
|
602
|
-
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual(
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'test1'], baseLocation)).toEqual(
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
});
|
|
644
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual(
|
|
645
|
+
[]
|
|
646
|
+
);
|
|
647
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'bar'], baseLocation)).toEqual(
|
|
648
|
+
[]
|
|
649
|
+
);
|
|
650
|
+
expect(asserts.requireAny(Object.keys(fakeNode), [], baseLocation)).toEqual([
|
|
651
|
+
{
|
|
652
|
+
message: 'Should have any of ',
|
|
653
|
+
location: baseLocation.key(),
|
|
654
|
+
},
|
|
655
|
+
]);
|
|
656
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'test1'], baseLocation)).toEqual([
|
|
657
|
+
{
|
|
658
|
+
message: 'Should have any of test, test1',
|
|
659
|
+
location: baseLocation.key(),
|
|
660
|
+
},
|
|
661
|
+
]);
|
|
662
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual([]);
|
|
622
663
|
expect(
|
|
623
664
|
asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)
|
|
624
|
-
).toEqual(
|
|
665
|
+
).toEqual([]);
|
|
666
|
+
});
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
describe('function', () => {
|
|
670
|
+
it('node must have at least one property from predefined list', () => {
|
|
671
|
+
const customFn = jest.fn((value: string[], options: any, location: Location) => {
|
|
672
|
+
if (value[0] === options.word) {
|
|
673
|
+
return [{ message: `First value should be ${options.word}`, location: location.key() }];
|
|
674
|
+
}
|
|
675
|
+
return [];
|
|
676
|
+
});
|
|
677
|
+
asserts['local/customFn'] = buildAssertCustomFunction(customFn);
|
|
678
|
+
expect(
|
|
679
|
+
asserts['local/customFn'](Object.keys(fakeNode), { word: 'foo' }, baseLocation)
|
|
680
|
+
).toEqual([
|
|
681
|
+
{
|
|
682
|
+
message: 'First value should be foo',
|
|
683
|
+
location: baseLocation.key(),
|
|
684
|
+
},
|
|
685
|
+
]);
|
|
686
|
+
expect(customFn.mock.calls.length).toBe(1);
|
|
687
|
+
expect(customFn.mock.calls[0][0]).toEqual(Object.keys(fakeNode));
|
|
625
688
|
});
|
|
626
689
|
});
|
|
627
690
|
});
|