@redocly/openapi-core 1.0.0-beta.108 → 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.
Files changed (159) hide show
  1. package/README.md +2 -2
  2. package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
  3. package/lib/bundle.d.ts +1 -1
  4. package/lib/bundle.js +4 -4
  5. package/lib/config/all.js +3 -1
  6. package/lib/config/config-resolvers.js +22 -4
  7. package/lib/config/config.d.ts +1 -0
  8. package/lib/config/config.js +1 -0
  9. package/lib/config/load.d.ts +8 -2
  10. package/lib/config/load.js +4 -2
  11. package/lib/config/minimal.js +3 -1
  12. package/lib/config/recommended.js +3 -1
  13. package/lib/config/rules.js +1 -1
  14. package/lib/config/types.d.ts +17 -0
  15. package/lib/config/utils.d.ts +2 -2
  16. package/lib/config/utils.js +44 -6
  17. package/lib/decorators/common/registry-dependencies.js +1 -1
  18. package/lib/format/format.d.ts +1 -1
  19. package/lib/format/format.js +22 -1
  20. package/lib/lint.js +2 -2
  21. package/lib/redocly/registry-api.d.ts +0 -1
  22. package/lib/redocly/registry-api.js +5 -4
  23. package/lib/resolve.js +3 -1
  24. package/lib/rules/ajv.d.ts +1 -1
  25. package/lib/rules/ajv.js +5 -5
  26. package/lib/rules/common/assertions/asserts.d.ts +3 -5
  27. package/lib/rules/common/assertions/asserts.js +137 -97
  28. package/lib/rules/common/assertions/index.js +2 -6
  29. package/lib/rules/common/assertions/utils.d.ts +12 -6
  30. package/lib/rules/common/assertions/utils.js +33 -20
  31. package/lib/rules/common/no-ambiguous-paths.js +1 -1
  32. package/lib/rules/common/no-identical-paths.js +1 -1
  33. package/lib/rules/common/operation-2xx-response.js +1 -1
  34. package/lib/rules/common/operation-4xx-response.js +1 -1
  35. package/lib/rules/common/operation-operationId.js +1 -1
  36. package/lib/rules/common/operation-tag-defined.js +1 -1
  37. package/lib/rules/common/path-not-include-query.js +1 -1
  38. package/lib/rules/common/security-defined.d.ts +2 -0
  39. package/lib/rules/common/{operation-security-defined.js → security-defined.js} +18 -4
  40. package/lib/rules/common/spec.js +12 -1
  41. package/lib/rules/common/tags-alphabetical.js +1 -1
  42. package/lib/rules/oas2/index.d.ts +1 -1
  43. package/lib/rules/oas2/index.js +2 -2
  44. package/lib/rules/oas2/remove-unused-components.js +1 -1
  45. package/lib/rules/oas2/request-mime-type.js +1 -1
  46. package/lib/rules/oas2/response-mime-type.js +1 -1
  47. package/lib/rules/oas3/index.js +6 -2
  48. package/lib/rules/oas3/no-empty-servers.js +1 -1
  49. package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -1
  50. package/lib/rules/oas3/no-unused-components.js +1 -1
  51. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
  52. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
  53. package/lib/rules/oas3/remove-unused-components.js +1 -1
  54. package/lib/rules/oas3/request-mime-type.js +1 -1
  55. package/lib/rules/oas3/response-mime-type.js +1 -1
  56. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
  57. package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
  58. package/lib/rules/other/stats.d.ts +2 -2
  59. package/lib/rules/other/stats.js +2 -2
  60. package/lib/rules/utils.js +1 -1
  61. package/lib/types/oas2.js +5 -5
  62. package/lib/types/oas3.js +27 -20
  63. package/lib/types/oas3_1.js +3 -3
  64. package/lib/types/redocly-yaml.js +60 -54
  65. package/lib/utils.d.ts +3 -3
  66. package/lib/utils.js +5 -5
  67. package/lib/visitors.d.ts +11 -11
  68. package/lib/visitors.js +13 -1
  69. package/package.json +3 -5
  70. package/src/__tests__/__snapshots__/bundle.test.ts.snap +3 -3
  71. package/src/__tests__/fixtures/extension.js +3 -3
  72. package/src/__tests__/format.test.ts +76 -0
  73. package/src/__tests__/lint.test.ts +184 -121
  74. package/src/__tests__/resolve-http.test.ts +1 -1
  75. package/src/__tests__/resolve.test.ts +9 -9
  76. package/src/__tests__/walk.test.ts +78 -10
  77. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  78. package/src/bundle.ts +4 -4
  79. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +6 -2
  80. package/src/config/__tests__/config-resolvers.test.ts +37 -1
  81. package/src/config/__tests__/config.test.ts +5 -0
  82. package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
  83. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
  84. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
  85. package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +16 -0
  86. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
  87. package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +16 -0
  88. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
  89. package/src/config/__tests__/fixtures/resolve-config/plugin.js +11 -0
  90. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
  91. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
  92. package/src/config/__tests__/load.test.ts +13 -16
  93. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  94. package/src/config/__tests__/utils.test.ts +64 -4
  95. package/src/config/all.ts +3 -1
  96. package/src/config/config-resolvers.ts +30 -7
  97. package/src/config/config.ts +2 -0
  98. package/src/config/load.ts +13 -6
  99. package/src/config/minimal.ts +3 -1
  100. package/src/config/recommended.ts +3 -1
  101. package/src/config/rules.ts +2 -2
  102. package/src/config/types.ts +24 -0
  103. package/src/config/utils.ts +103 -13
  104. package/src/decorators/common/registry-dependencies.ts +1 -1
  105. package/src/format/format.ts +32 -2
  106. package/src/lint.ts +2 -2
  107. package/src/redocly/registry-api.ts +5 -4
  108. package/src/resolve.ts +3 -1
  109. package/src/rules/__tests__/utils.test.ts +1 -1
  110. package/src/rules/ajv.ts +4 -4
  111. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
  112. package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
  113. package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
  114. package/src/rules/common/__tests__/security-defined.test.ts +175 -0
  115. package/src/rules/common/__tests__/spec.test.ts +79 -0
  116. package/src/rules/common/assertions/__tests__/asserts.test.ts +491 -428
  117. package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
  118. package/src/rules/common/assertions/asserts.ts +155 -97
  119. package/src/rules/common/assertions/index.ts +2 -11
  120. package/src/rules/common/assertions/utils.ts +66 -36
  121. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  122. package/src/rules/common/no-identical-paths.ts +1 -1
  123. package/src/rules/common/operation-2xx-response.ts +1 -1
  124. package/src/rules/common/operation-4xx-response.ts +1 -1
  125. package/src/rules/common/operation-operationId.ts +1 -1
  126. package/src/rules/common/operation-tag-defined.ts +1 -1
  127. package/src/rules/common/path-not-include-query.ts +1 -1
  128. package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +19 -4
  129. package/src/rules/common/spec.ts +15 -1
  130. package/src/rules/common/tags-alphabetical.ts +1 -1
  131. package/src/rules/oas2/index.ts +2 -2
  132. package/src/rules/oas2/remove-unused-components.ts +1 -1
  133. package/src/rules/oas2/request-mime-type.ts +1 -1
  134. package/src/rules/oas2/response-mime-type.ts +1 -1
  135. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +51 -2
  136. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
  137. package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
  138. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
  139. package/src/rules/oas3/index.ts +6 -2
  140. package/src/rules/oas3/no-empty-servers.ts +1 -1
  141. package/src/rules/oas3/no-server-variables-empty-enum.ts +1 -1
  142. package/src/rules/oas3/no-unused-components.ts +1 -1
  143. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
  144. package/src/rules/oas3/remove-unused-components.ts +1 -1
  145. package/src/rules/oas3/request-mime-type.ts +1 -1
  146. package/src/rules/oas3/response-mime-type.ts +1 -1
  147. package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
  148. package/src/rules/other/stats.ts +2 -2
  149. package/src/rules/utils.ts +2 -1
  150. package/src/types/index.ts +2 -2
  151. package/src/types/oas2.ts +5 -5
  152. package/src/types/oas3.ts +27 -20
  153. package/src/types/oas3_1.ts +3 -3
  154. package/src/types/redocly-yaml.ts +66 -38
  155. package/src/utils.ts +11 -7
  156. package/src/visitors.ts +29 -13
  157. package/tsconfig.tsbuildinfo +1 -1
  158. package/lib/rules/common/operation-security-defined.d.ts +0 -2
  159. package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
@@ -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({ isValid: true });
18
- expect(asserts.pattern('test string', '/test me/', baseLocation)).toEqual({
19
- isValid: false,
20
- location: baseLocation,
21
- });
22
- expect(asserts.pattern(['test string', 'test me'], '/test/', baseLocation)).toEqual({
23
- isValid: true,
24
- });
25
- expect(asserts.pattern(['test string', 'test me'], '/test me/', baseLocation)).toEqual({
26
- isValid: false,
27
- location: baseLocation.key(),
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({ isValid: true });
34
+ ).toEqual([]);
36
35
  expect(
37
36
  asserts.pattern('./other.yaml', '/^(./)?components/.*.yaml$/', baseLocation)
38
- ).toEqual({ isValid: false, location: baseLocation });
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
- isValid: true,
46
- location: baseLocation,
47
- });
48
- expect(asserts.ref({}, true, baseLocation, {})).toEqual({
49
- isValid: false,
50
- location: baseLocation.key(),
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
- isValid: false,
57
- location: baseLocation,
58
- });
59
- expect(asserts.ref({}, false, baseLocation, {})).toEqual({
60
- isValid: true,
61
- location: baseLocation.key(),
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({ isValid: true, location: baseLocation });
70
+ ).toEqual([]);
69
71
  expect(
70
72
  asserts.ref({ $ref: 'test string' }, '/test me/', baseLocation, { $ref: 'test string' })
71
- ).toEqual({ isValid: false, location: baseLocation });
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({ isValid: true, location: baseLocation });
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({ isValid: false, location: baseLocation });
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({ isValid: true });
94
- expect(asserts.enum(['test'], ['test', 'example'], baseLocation)).toEqual({
95
- isValid: true,
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
- { isValid: false, location: baseLocation.child('foo').key() }
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
- isValid: false,
105
- location: baseLocation,
106
- });
107
- expect(asserts.enum(['test', 'foo'], ['test', 'example'], baseLocation)).toEqual({
108
- isValid: false,
109
- location: baseLocation.child('foo').key(),
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
- isValid: true,
118
- location: baseLocation,
119
- });
120
- expect(asserts.defined(undefined, true, baseLocation)).toEqual({
121
- isValid: false,
122
- location: baseLocation,
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
- isValid: true,
128
- location: baseLocation,
129
- });
130
- expect(asserts.defined('test', false, baseLocation)).toEqual({
131
- isValid: false,
132
- location: baseLocation,
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
- isValid: true,
141
- location: baseLocation,
142
- });
143
- expect(asserts.undefined('test', true, baseLocation)).toEqual({
144
- isValid: false,
145
- location: baseLocation,
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
- isValid: true,
151
- location: baseLocation,
152
- });
153
- expect(asserts.undefined(undefined, false, baseLocation)).toEqual({
154
- isValid: false,
155
- location: baseLocation,
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
- isValid: true,
164
- });
165
- expect(asserts.required(['one', 'two'], ['one', 'two', 'three'], baseLocation)).toEqual({
166
- isValid: false,
167
- location: baseLocation.key(),
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
- isValid: true,
176
- location: baseLocation,
177
- });
178
- expect(asserts.nonEmpty('', true, baseLocation)).toEqual({
179
- isValid: false,
180
- location: baseLocation,
181
- });
182
- expect(asserts.nonEmpty(null, true, baseLocation)).toEqual({
183
- isValid: false,
184
- location: baseLocation,
185
- });
186
- expect(asserts.nonEmpty(undefined, true, baseLocation)).toEqual({
187
- isValid: false,
188
- location: baseLocation,
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
- isValid: true,
194
- location: baseLocation,
195
- });
196
- expect(asserts.nonEmpty(null, false, baseLocation)).toEqual({
197
- isValid: true,
198
- location: baseLocation,
199
- });
200
- expect(asserts.nonEmpty(undefined, false, baseLocation)).toEqual({
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
- isValid: false,
215
- location: baseLocation,
216
- });
217
- expect(asserts.minLength([1, 2, 3, 4], 5, baseLocation)).toEqual({
218
- isValid: false,
219
- location: baseLocation,
220
- });
221
- expect(asserts.minLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual({
222
- isValid: true,
223
- location: baseLocation,
224
- });
225
- expect(asserts.minLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual({
226
- isValid: true,
227
- location: baseLocation,
228
- });
229
- expect(asserts.minLength('example', 5, baseLocation)).toEqual({
230
- isValid: true,
231
- location: baseLocation,
232
- });
233
- expect(asserts.minLength([], 5, baseLocation)).toEqual({
234
- isValid: false,
235
- location: baseLocation,
236
- });
237
- expect(asserts.minLength('', 5, baseLocation)).toEqual({
238
- isValid: false,
239
- location: baseLocation,
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
- isValid: true,
248
- location: baseLocation,
249
- });
250
- expect(asserts.maxLength([1, 2, 3, 4], 5, baseLocation)).toEqual({
251
- isValid: true,
252
- location: baseLocation,
253
- });
254
- expect(asserts.maxLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual({
255
- isValid: true,
256
- location: baseLocation,
257
- });
258
- expect(asserts.maxLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual({
259
- isValid: false,
260
- location: baseLocation,
261
- });
262
- expect(asserts.maxLength('example', 5, baseLocation)).toEqual({
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
- isValid: true,
281
- });
282
- expect(asserts.casing(['testExample', 'FooBar'], 'camelCase', baseLocation)).toEqual({
283
- isValid: false,
284
- location: baseLocation.child('FooBar').key(),
285
- });
286
- expect(asserts.casing('testExample', 'camelCase', baseLocation)).toEqual({ isValid: true });
287
- expect(asserts.casing('TestExample', 'camelCase', baseLocation)).toEqual({
288
- isValid: false,
289
- location: baseLocation,
290
- });
291
- expect(asserts.casing('test-example', 'camelCase', baseLocation)).toEqual({
292
- isValid: false,
293
- location: baseLocation,
294
- });
295
- expect(asserts.casing('test_example', 'camelCase', baseLocation)).toEqual({
296
- isValid: false,
297
- location: baseLocation,
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
- isValid: true,
303
- });
304
- expect(asserts.casing(['TestExample', 'FooBar'], 'PascalCase', baseLocation)).toEqual({
305
- isValid: true,
306
- });
307
- expect(asserts.casing(['TestExample', 'fooBar'], 'PascalCase', baseLocation)).toEqual({
308
- isValid: false,
309
- location: baseLocation.child('fooBar').key(),
310
- });
311
- expect(asserts.casing('testExample', 'PascalCase', baseLocation)).toEqual({
312
- isValid: false,
313
- location: baseLocation,
314
- });
315
- expect(asserts.casing('test-example', 'PascalCase', baseLocation)).toEqual({
316
- isValid: false,
317
- location: baseLocation,
318
- });
319
- expect(asserts.casing('test_example', 'PascalCase', baseLocation)).toEqual({
320
- isValid: false,
321
- location: baseLocation,
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
- isValid: true,
327
- });
328
- expect(asserts.casing(['test-example', 'foo-bar'], 'kebab-case', baseLocation)).toEqual({
329
- isValid: true,
330
- });
331
- expect(asserts.casing(['test-example', 'foo_bar'], 'kebab-case', baseLocation)).toEqual({
332
- isValid: false,
333
- location: baseLocation.child('foo_bar').key(),
334
- });
335
- expect(asserts.casing('testExample', 'kebab-case', baseLocation)).toEqual({
336
- isValid: false,
337
- location: baseLocation,
338
- });
339
- expect(asserts.casing('TestExample', 'kebab-case', baseLocation)).toEqual({
340
- isValid: false,
341
- location: baseLocation,
342
- });
343
- expect(asserts.casing('test_example', 'kebab-case', baseLocation)).toEqual({
344
- isValid: false,
345
- location: baseLocation,
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
- isValid: true,
351
- });
352
- expect(asserts.casing(['test_example', 'foo_bar'], 'snake_case', baseLocation)).toEqual({
353
- isValid: true,
354
- });
355
- expect(asserts.casing(['test_example', 'foo-bar'], 'snake_case', baseLocation)).toEqual({
356
- isValid: false,
357
- location: baseLocation.child('foo-bar').key(),
358
- });
359
- expect(asserts.casing('testExample', 'snake_case', baseLocation)).toEqual({
360
- isValid: false,
361
- location: baseLocation,
362
- });
363
- expect(asserts.casing('TestExample', 'snake_case', baseLocation)).toEqual({
364
- isValid: false,
365
- location: baseLocation,
366
- });
367
- expect(asserts.casing('test-example', 'snake_case', baseLocation)).toEqual({
368
- isValid: false,
369
- location: baseLocation,
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
- isValid: true,
375
- });
376
- expect(asserts.casing(['TEST_EXAMPLE', 'FOO_BAR'], 'MACRO_CASE', baseLocation)).toEqual({
377
- isValid: true,
378
- });
379
- expect(asserts.casing(['TEST_EXAMPLE', 'FOO-BAR'], 'MACRO_CASE', baseLocation)).toEqual({
380
- isValid: false,
381
- location: baseLocation.child('FOO-BAR').key(),
382
- });
383
- expect(asserts.casing('TEST_EXAMPLE_', 'MACRO_CASE', baseLocation)).toEqual({
384
- isValid: false,
385
- location: baseLocation,
386
- });
387
- expect(asserts.casing('_TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({
388
- isValid: false,
389
- location: baseLocation,
390
- });
391
- expect(asserts.casing('TEST__EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({
392
- isValid: false,
393
- location: baseLocation,
394
- });
395
- expect(asserts.casing('TEST-EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({
396
- isValid: false,
397
- location: baseLocation,
398
- });
399
- expect(asserts.casing('testExample', 'MACRO_CASE', baseLocation)).toEqual({
400
- isValid: false,
401
- location: baseLocation,
402
- });
403
- expect(asserts.casing('TestExample', 'MACRO_CASE', baseLocation)).toEqual({
404
- isValid: false,
405
- location: baseLocation,
406
- });
407
- expect(asserts.casing('test-example', 'MACRO_CASE', baseLocation)).toEqual({
408
- isValid: false,
409
- location: baseLocation,
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
- isValid: true,
415
- });
416
- expect(asserts.casing(['TEST-EXAMPLE', 'FOO-BAR'], 'COBOL-CASE', baseLocation)).toEqual({
417
- isValid: true,
418
- });
419
- expect(asserts.casing(['TEST-EXAMPLE', 'FOO_BAR'], 'COBOL-CASE', baseLocation)).toEqual({
420
- isValid: false,
421
- location: baseLocation.child('FOO_BAR').key(),
422
- });
423
- expect(asserts.casing('TEST-EXAMPLE-', 'COBOL-CASE', baseLocation)).toEqual({
424
- isValid: false,
425
- location: baseLocation,
426
- });
427
- expect(asserts.casing('0TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
428
- isValid: false,
429
- location: baseLocation,
430
- });
431
- expect(asserts.casing('-TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
432
- isValid: false,
433
- location: baseLocation,
434
- });
435
- expect(asserts.casing('TEST--EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
436
- isValid: false,
437
- location: baseLocation,
438
- });
439
- expect(asserts.casing('TEST_EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({
440
- isValid: false,
441
- location: baseLocation,
442
- });
443
- expect(asserts.casing('testExample', 'COBOL-CASE', baseLocation)).toEqual({
444
- isValid: false,
445
- location: baseLocation,
446
- });
447
- expect(asserts.casing('TestExample', 'COBOL-CASE', baseLocation)).toEqual({
448
- isValid: false,
449
- location: baseLocation,
450
- });
451
- expect(asserts.casing('test-example', 'COBOL-CASE', baseLocation)).toEqual({
452
- isValid: false,
453
- location: baseLocation,
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({ isValid: true });
458
- expect(asserts.casing(['testexample', 'foobar'], 'flatcase', baseLocation)).toEqual({
459
- isValid: true,
460
- });
461
- expect(asserts.casing(['testexample', 'foo_bar'], 'flatcase', baseLocation)).toEqual({
462
- isValid: false,
463
- location: baseLocation.child('foo_bar').key(),
464
- });
465
- expect(asserts.casing('testexample_', 'flatcase', baseLocation)).toEqual({
466
- isValid: false,
467
- location: baseLocation,
468
- });
469
- expect(asserts.casing('0testexample', 'flatcase', baseLocation)).toEqual({
470
- isValid: false,
471
- location: baseLocation,
472
- });
473
- expect(asserts.casing('testExample', 'flatcase', baseLocation)).toEqual({
474
- isValid: false,
475
- location: baseLocation,
476
- });
477
- expect(asserts.casing('TestExample', 'flatcase', baseLocation)).toEqual({
478
- isValid: false,
479
- location: baseLocation,
480
- });
481
- expect(asserts.casing('test-example', 'flatcase', baseLocation)).toEqual({
482
- isValid: false,
483
- location: baseLocation,
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({ isValid: true, location: baseLocation });
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({ isValid: true, location: baseLocation });
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({ isValid: true, location: baseLocation });
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({ isValid: true, location: baseLocation });
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({ isValid: true, location: baseLocation.key() });
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({ isValid: false, location: baseLocation.key() });
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({ isValid: false, location: baseLocation.key() });
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({ isValid: true, location: baseLocation.key() });
621
+ ).toEqual([]);
584
622
  expect(
585
623
  asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'baz'], baseLocation)
586
- ).toEqual({ isValid: true, location: baseLocation.key() });
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({ isValid: false, location: baseLocation.key() });
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({ isValid: false, location: baseLocation.key() });
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
- isValid: true,
604
- location: baseLocation.key(),
605
- });
606
- expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'bar'], baseLocation)).toEqual({
607
- isValid: true,
608
- location: baseLocation.key(),
609
- });
610
- expect(asserts.requireAny(Object.keys(fakeNode), [], baseLocation)).toEqual({
611
- isValid: false,
612
- location: baseLocation.key(),
613
- });
614
- expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'test1'], baseLocation)).toEqual({
615
- isValid: false,
616
- location: baseLocation.key(),
617
- });
618
- expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual({
619
- isValid: true,
620
- location: baseLocation.key(),
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({ isValid: true, location: baseLocation.key() });
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
  });