@squiz/dx-json-schema-lib 1.21.1-alpha.2 → 1.21.1-alpha.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. package/.npm/_logs/2023-03-17T05_05_36_315Z-debug-0.log +37 -0
  2. package/lib/JsonValidationService.d.ts +1 -1
  3. package/lib/JsonValidationService.js +23 -5
  4. package/lib/JsonValidationService.js.map +1 -1
  5. package/lib/JsonValidationService.spec.js +469 -426
  6. package/lib/JsonValidationService.spec.js.map +1 -1
  7. package/lib/index.d.ts +6 -1
  8. package/lib/index.js +6 -1
  9. package/lib/index.js.map +1 -1
  10. package/lib/jsonTypeResolution/{arbitraryTypeResolution.d.ts → TypeResolver.d.ts} +7 -12
  11. package/lib/jsonTypeResolution/{arbitraryTypeResolution.js → TypeResolver.js} +17 -17
  12. package/lib/jsonTypeResolution/TypeResolver.js.map +1 -0
  13. package/lib/jsonTypeResolution/{arbitraryTypeResolution.spec.js → TypeResolver.spec.js} +12 -39
  14. package/lib/jsonTypeResolution/TypeResolver.spec.js.map +1 -0
  15. package/lib/jsonTypeResolution/TypeResolverBuilder.d.ts +12 -0
  16. package/lib/jsonTypeResolution/TypeResolverBuilder.js +32 -0
  17. package/lib/jsonTypeResolution/TypeResolverBuilder.js.map +1 -0
  18. package/lib/manifest/v1/DxContentMetaSchema.json +117 -2
  19. package/lib/manifest/v1/MatrixAssetSchema.json +390 -0
  20. package/lib/manifest/v1/__test__/schemas/inputStringWithFormat.json +29 -0
  21. package/lib/manifest/v1/subSchemas.d.ts +2 -1
  22. package/lib/manifest/v1/subSchemas.js +3 -1
  23. package/lib/manifest/v1/subSchemas.js.map +1 -1
  24. package/lib/manifest/v1/v1.d.ts +405 -4
  25. package/lib/manifest/v1/v1.json +48 -0
  26. package/lib/primitiveTypes/FormattedText.d.ts +8 -0
  27. package/lib/primitiveTypes/FormattedText.js +21 -0
  28. package/lib/primitiveTypes/FormattedText.js.map +1 -0
  29. package/lib/primitiveTypes/SquizImage.d.ts +26 -0
  30. package/lib/primitiveTypes/SquizImage.js +105 -0
  31. package/lib/primitiveTypes/SquizImage.js.map +1 -0
  32. package/lib/primitiveTypes/index.d.ts +2 -0
  33. package/lib/primitiveTypes/index.js +19 -0
  34. package/lib/primitiveTypes/index.js.map +1 -0
  35. package/lib/resolvableTypes/MatrixAsset.d.ts +9 -0
  36. package/lib/resolvableTypes/MatrixAsset.js +21 -0
  37. package/lib/resolvableTypes/MatrixAsset.js.map +1 -0
  38. package/lib/resolvableTypes/index.d.ts +1 -0
  39. package/lib/resolvableTypes/index.js +18 -0
  40. package/lib/resolvableTypes/index.js.map +1 -0
  41. package/lib/validators/customFormatValidators.d.ts +2 -0
  42. package/lib/validators/customFormatValidators.js +14 -0
  43. package/lib/validators/customFormatValidators.js.map +1 -0
  44. package/lib/validators/utils/matrixAssetValidator.d.ts +2 -0
  45. package/lib/validators/utils/matrixAssetValidator.js +11 -0
  46. package/lib/validators/utils/matrixAssetValidator.js.map +1 -0
  47. package/lib/validators/utils/matrixAssetValidator.spec.d.ts +1 -0
  48. package/lib/validators/utils/matrixAssetValidator.spec.js +43 -0
  49. package/lib/validators/utils/matrixAssetValidator.spec.js.map +1 -0
  50. package/package.json +5 -4
  51. package/src/JsonValidationService.spec.ts +596 -533
  52. package/src/JsonValidationService.ts +28 -10
  53. package/src/index.ts +8 -1
  54. package/src/jsonTypeResolution/{arbitraryTypeResolution.spec.ts → TypeResolver.spec.ts} +23 -70
  55. package/src/jsonTypeResolution/{arbitraryTypeResolution.ts → TypeResolver.ts} +27 -23
  56. package/src/jsonTypeResolution/TypeResolverBuilder.ts +43 -0
  57. package/src/manifest/v1/DxContentMetaSchema.json +117 -2
  58. package/src/manifest/v1/MatrixAssetSchema.json +391 -0
  59. package/src/manifest/v1/__test__/schemas/inputStringWithFormat.json +29 -0
  60. package/src/manifest/v1/subSchemas.ts +2 -1
  61. package/src/manifest/v1/v1.json +48 -0
  62. package/src/manifest/v1/v1.ts +657 -6
  63. package/src/primitiveTypes/FormattedText.ts +24 -0
  64. package/src/primitiveTypes/SquizImage.ts +128 -0
  65. package/src/primitiveTypes/index.ts +2 -0
  66. package/src/resolvableTypes/MatrixAsset.ts +24 -0
  67. package/src/resolvableTypes/index.ts +1 -0
  68. package/src/validators/customFormatValidators.ts +15 -0
  69. package/src/validators/utils/matrixAssetValidator.spec.ts +49 -0
  70. package/src/validators/utils/matrixAssetValidator.ts +8 -0
  71. package/tsconfig.tsbuildinfo +1 -1
  72. package/.npm/_logs/2023-03-02T03_26_09_372Z-debug-0.log +0 -39
  73. package/lib/jsonTypeResolution/arbitraryTypeResolution.js.map +0 -1
  74. package/lib/jsonTypeResolution/arbitraryTypeResolution.spec.js.map +0 -1
  75. package/lib/jsonTypeResolution/index.d.ts +0 -76
  76. package/lib/jsonTypeResolution/index.js +0 -35
  77. package/lib/jsonTypeResolution/index.js.map +0 -1
  78. package/lib/jsonTypeResolution/primitiveTypes.d.ts +0 -10
  79. package/lib/jsonTypeResolution/primitiveTypes.js +0 -27
  80. package/lib/jsonTypeResolution/primitiveTypes.js.map +0 -1
  81. package/lib/jsonTypeResolution/resolvableTypes.d.ts +0 -12
  82. package/lib/jsonTypeResolution/resolvableTypes.js +0 -30
  83. package/lib/jsonTypeResolution/resolvableTypes.js.map +0 -1
  84. package/src/jsonTypeResolution/index.ts +0 -16
  85. package/src/jsonTypeResolution/primitiveTypes.ts +0 -32
  86. package/src/jsonTypeResolution/resolvableTypes.ts +0 -37
  87. /package/lib/jsonTypeResolution/{arbitraryTypeResolution.spec.d.ts → TypeResolver.spec.d.ts} +0 -0
@@ -7,7 +7,9 @@ const JsonValidationService_1 = require("./JsonValidationService");
7
7
  const SchemaValidationError_1 = require("./errors/SchemaValidationError");
8
8
  const validComponent_json_1 = __importDefault(require("./manifest/v1/__test__/schemas/validComponent.json"));
9
9
  const validComponentJson_json_1 = __importDefault(require("./manifest/v1/__test__/schemas/validComponentJson.json"));
10
- const arbitraryTypeResolution_1 = require("./jsonTypeResolution/arbitraryTypeResolution");
10
+ const inputStringWithFormat_json_1 = __importDefault(require("./manifest/v1/__test__/schemas/inputStringWithFormat.json"));
11
+ const TypeResolver_1 = require("./jsonTypeResolution/TypeResolver");
12
+ const primitiveTypes_1 = require("./primitiveTypes");
11
13
  // eslint-disable-next-line @typescript-eslint/ban-types
12
14
  function expectToThrowErrorMatchingTypeAndMessage(received, errorType, message) {
13
15
  let error = null;
@@ -44,403 +46,51 @@ describe('JsonValidationService', () => {
44
46
  jsonValidationService.validateManifest(validComponent_json_1.default, 'invalid-version');
45
47
  }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Invalid manifest version');
46
48
  });
47
- });
48
- describe('validateContentSchema', () => {
49
- it('should return true for a valid content schema', () => {
50
- const contentSchema = {
51
- type: 'object',
52
- properties: {
53
- 'my-input': { type: 'number' },
54
- },
55
- required: ['my-input'],
56
- };
57
- const result = jsonValidationService.validateContentSchema(contentSchema);
49
+ it('should return true for a valid manifest with a string format MatrixAssetUri', () => {
50
+ const result = jsonValidationService.validateManifest(inputStringWithFormat_json_1.default, 'v1');
58
51
  expect(result).toBe(true);
59
52
  });
60
- it('should return false for an invalid content schema, where the required property is missed from a child object', () => {
61
- const contentSchema = {
62
- type: 'object',
63
- properties: {
64
- 'my-input': {
65
- type: 'object',
66
- properties: {
67
- 'my-deep-input': { type: 'object' },
68
- },
69
- },
70
- },
71
- required: ['my-input'],
72
- };
73
- expectToThrowErrorMatchingTypeAndMessage(() => {
74
- jsonValidationService.validateContentSchema(contentSchema);
75
- }, SchemaValidationError_1.SchemaValidationError, 'failed validation: The required property `required` is missing at `#/properties/my-input`');
76
- });
77
- it('should throw a SchemaValidationError for an invalid content schema, top level type must be object', () => {
78
- const contentSchema = {
79
- type: 'array',
80
- items: {
81
- type: 'object',
82
- properties: {
83
- 'my-input': { type: 'number' },
84
- },
85
- required: ['my-input'],
86
- },
87
- };
88
- expectToThrowErrorMatchingTypeAndMessage(() => {
89
- jsonValidationService.validateContentSchema(contentSchema);
90
- }, SchemaValidationError_1.SchemaValidationError, `failed validation: Expected value at \`#/type\` to be \`object\`, but value given is \`array\``);
91
- });
92
- it('should throw a SchemaValidationError for an invalid content schema missing the required property', () => {
93
- const contentSchema = {
94
- type: 'object',
95
- properties: {
96
- 'my-input': { type: 'number' },
97
- },
98
- };
99
- expectToThrowErrorMatchingTypeAndMessage(() => {
100
- jsonValidationService.validateContentSchema(contentSchema);
101
- }, SchemaValidationError_1.SchemaValidationError, 'failed validation: The required property `required` is missing at `#`');
102
- });
103
53
  });
104
- describe('validateComponentInput', () => {
105
- describe('FormattedText input', () => {
106
- it('should handle type as an array', () => {
107
- const functionInputSchema = {
108
- type: 'object',
109
- properties: {
110
- 'my-input': { type: ['number', 'string'] },
111
- },
112
- required: ['my-input'],
113
- };
114
- expect(jsonValidationService.validateComponentInput(functionInputSchema, {
115
- 'my-input': 'formattedText',
116
- })).toEqual(true);
117
- expect(jsonValidationService.validateComponentInput(functionInputSchema, {
118
- 'my-input': 123,
119
- })).toEqual(true);
120
- });
121
- it('should handle type is an array of both string and FormattedText', () => {
122
- const formattedText = [
123
- {
124
- tag: 'p',
125
- type: 'tag',
126
- children: [
127
- { type: 'text', value: 'This is some ' },
128
- { type: 'text', value: 'Link to asset 12345' },
129
- { type: 'text', value: ' with an image ' },
130
- { type: 'text', value: '.' },
131
- ],
132
- },
133
- ];
134
- const functionInputSchema = {
135
- type: 'object',
136
- properties: {
137
- 'my-input': { type: ['FormattedText', 'string'] },
138
- },
139
- required: ['my-input'],
140
- };
141
- expect(jsonValidationService.validateComponentInput(functionInputSchema, {
142
- 'my-input': formattedText,
143
- })).toEqual(true);
144
- expect(jsonValidationService.validateComponentInput(functionInputSchema, {
145
- 'my-input': 'hello',
146
- })).toEqual(true);
147
- });
148
- it('should return true if input is formatted text', () => {
149
- const functionInputSchema = {
150
- type: 'object',
151
- properties: {
152
- 'my-input': { type: 'FormattedText' },
153
- },
154
- required: ['my-input'],
155
- };
156
- const formattedText = [
157
- {
158
- tag: 'p',
159
- type: 'tag',
160
- children: [
161
- { type: 'text', value: 'This is some ' },
162
- { type: 'text', value: 'Link to asset 12345' },
163
- { type: 'text', value: ' with an image ' },
164
- { type: 'text', value: '.' },
165
- ],
166
- },
167
- ];
168
- const inputValue = {
169
- 'my-input': formattedText,
170
- };
171
- expect(jsonValidationService.validateComponentInput(functionInputSchema, inputValue)).toEqual(true);
172
- });
173
- it('should throw an error if the FormattedText input is not formatted text', () => {
174
- const functionInputSchema = {
175
- type: 'object',
176
- properties: {
177
- 'my-input': { type: 'FormattedText' },
178
- },
179
- required: ['my-input'],
180
- };
181
- const inputValue = {
182
- 'my-input': 123,
183
- };
184
- expectToThrowErrorMatchingTypeAndMessage(() => {
185
- jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
186
- }, SchemaValidationError_1.SchemaValidationError, `failed validation: Expected \`123\` (number) in \`#/my-input\` to be of type \`array\``);
187
- });
188
- it('should throw an error if the FormattedText input is invalid formatted text', () => {
189
- const functionInputSchema = {
190
- type: 'object',
191
- properties: {
192
- 'my-input': { type: 'FormattedText' },
193
- },
194
- required: ['my-input'],
195
- };
196
- const inputValue = {
197
- 'my-input': {
198
- something: 'aa',
199
- },
200
- };
201
- expectToThrowErrorMatchingTypeAndMessage(() => {
202
- jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
203
- }, SchemaValidationError_1.SchemaValidationError, `failed validation: Expected \`[object Object]\` (object) in \`#/my-input\` to be of type \`array\``);
204
- });
205
- it('should throw an error if the FormattedText input is invalid formatted text (deeply nested)', () => {
206
- const functionInputSchema = {
207
- type: 'object',
208
- properties: {
209
- 'my-input': { type: 'FormattedText' },
210
- },
211
- required: ['my-input'],
212
- };
213
- const formattedText = [
214
- {
215
- tag: 'p',
216
- type: 'tag',
217
- children: [
218
- { type: 'text', value: 'This is some ' },
219
- { type: 'text', value: 'Link to asset 12345' },
220
- { type: 'text', value: ' with an image ' },
221
- { type: 'text', value: 123 },
222
- { type: 'text', value: '.' },
223
- ],
224
- },
225
- ];
226
- const inputValue = {
227
- 'my-input': formattedText,
228
- };
229
- expectToThrowErrorMatchingTypeAndMessage(() => {
230
- jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
231
- }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Object at `#/my-input/0` does not match any schema');
232
- });
233
- it('should validate an array of formatted texts', () => {
234
- const formattedText = [
235
- {
236
- tag: 'p',
237
- type: 'tag',
238
- children: [{ type: 'text', value: 'hello' }],
239
- },
240
- ];
241
- const schema = {
242
- type: 'object',
243
- properties: {
244
- arr: {
245
- type: 'array',
246
- items: { type: 'FormattedText' },
247
- },
248
- },
249
- };
250
- const value = {
251
- arr: [formattedText],
252
- };
253
- expect(jsonValidationService.validateComponentInput(schema, value)).toEqual(true);
254
- });
255
- it('should throw an error if the FormattedText input is invalid formatted text (deeply, deeply nested)', () => {
256
- const formattedText = [
257
- {
258
- tag: 'p',
259
- type: 'tag',
260
- children: [{ type: 'text', value: 'hello' }],
261
- },
262
- ];
263
- const inputValue = {
264
- 'my-input': formattedText,
265
- deep: {
266
- arr: [
267
- {
268
- prop: formattedText,
269
- formattedTextArray: [formattedText, formattedText, { bad: 'data' }],
270
- },
271
- ],
272
- },
273
- };
274
- const functionInputSchema = {
275
- type: 'object',
276
- properties: {
277
- 'my-input': { type: 'FormattedText' },
278
- deep: {
279
- type: 'object',
280
- properties: {
281
- arr: {
282
- type: 'array',
283
- items: {
284
- type: 'object',
285
- required: ['prop', 'formattedTextArray'],
286
- properties: {
287
- prop: 'FormattedText',
288
- formattedTextArray: {
289
- type: 'array',
290
- items: {
291
- type: 'FormattedText',
292
- },
293
- },
294
- },
295
- },
296
- },
297
- },
298
- required: ['arr'],
299
- },
300
- },
301
- required: ['my-input', 'deep'],
302
- };
303
- expectToThrowErrorMatchingTypeAndMessage(() => {
304
- jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
305
- }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Expected `[object Object]` (object) in `#/deep/arr/0/formattedTextArray/2` to be of type `array`');
306
- });
307
- it('should validate a FormattedText value when the schema is a $ref', async () => {
308
- const formattedText = [
309
- {
310
- tag: 'p',
311
- type: 'tag',
312
- children: [{ type: 'text', value: 'hello' }],
313
- },
314
- ];
315
- const schema = {
316
- type: 'object',
317
- properties: {
318
- 'my-input': { $ref: '#/definitions/FormattedText' },
319
- },
320
- definitions: {
321
- FormattedText: { type: 'FormattedText' },
322
- },
323
- required: ['my-input'],
324
- };
325
- const value = {
326
- 'my-input': formattedText,
327
- };
328
- expect(jsonValidationService.validateComponentInput(schema, value)).toEqual(true);
329
- });
330
- it('should error when a FormattedText value is invalid when the schema is a $ref', async () => {
331
- const schema = {
332
- type: 'object',
333
- properties: {
334
- 'my-input': { $ref: '#/definitions/FormattedText' },
335
- },
336
- definitions: {
337
- FormattedText: { type: 'FormattedText' },
338
- },
339
- required: ['my-input'],
340
- };
341
- const value = {
342
- 'my-input': { bad: 'data' },
343
- };
344
- expectToThrowErrorMatchingTypeAndMessage(() => {
345
- jsonValidationService.validateComponentInput(schema, value);
346
- }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Expected `[object Object]` (object) in `#/my-input` to be of type `array`');
347
- });
348
- it('should validate a FormattedText value when the schema is a $ref to a $ref', async () => {
349
- const formattedText = [
350
- {
351
- tag: 'p',
352
- type: 'tag',
353
- children: [{ type: 'text', value: 'hello' }],
354
- },
355
- ];
356
- const schema = {
357
- type: 'object',
358
- properties: {
359
- 'my-input': { $ref: '#/definitions/FormattedText' },
360
- },
361
- definitions: {
362
- FormattedText: { $ref: '#/definitions/FormattedText2' },
363
- FormattedText2: { type: 'FormattedText' },
364
- },
365
- required: ['my-input'],
366
- };
367
- const value = {
368
- 'my-input': formattedText,
369
- };
370
- expect(jsonValidationService.validateComponentInput(schema, value)).toEqual(true);
371
- });
372
- it('should validate a FormattedText value when the schema is in an if/then/else', async () => {
373
- const formattedText = [
374
- {
375
- tag: 'p',
376
- type: 'tag',
377
- children: [{ type: 'text', value: 'hello' }],
378
- },
379
- ];
380
- const schema = {
381
- type: 'object',
382
- properties: {
383
- 'my-input': {
384
- if: { type: 'string' },
385
- then: { type: 'string' },
386
- else: { type: 'FormattedText' },
387
- },
388
- },
389
- required: ['my-input'],
390
- };
391
- const value = {
392
- 'my-input': formattedText,
393
- };
394
- expect(jsonValidationService.validateComponentInput(schema, value)).toEqual(true);
395
- });
396
- });
397
- describe('standard inputs', () => {
54
+ describe('validateRenderInput', () => {
55
+ describe('matrix-asset-uri input', () => {
398
56
  const functionInputSchema = {
399
57
  type: 'object',
400
58
  properties: {
401
- 'my-input': { type: 'number' },
59
+ 'matrix-asset': { type: 'string', format: 'matrix-asset-uri', matrixAssetTypes: ['image'] },
402
60
  },
403
- required: ['my-input'],
61
+ required: ['matrix-asset'],
404
62
  };
405
- it('should return true for valid input values', () => {
406
- const inputValue = {
407
- 'my-input': 123,
408
- };
409
- const result = jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
410
- expect(result).toBe(true);
63
+ it('should return true for valid a string with matrix-asset-uri format', () => {
64
+ const validMatrixAssetUri = 'matrix-asset://canary.uat.matrix.squiz.cloud/abc123';
65
+ expect(jsonValidationService.validateRenderInput(functionInputSchema, {
66
+ 'matrix-asset': validMatrixAssetUri,
67
+ })).toEqual(true);
411
68
  });
412
- it('should throw a SchemaValidationError for invalid input type', () => {
413
- const inputValue = {
414
- 'my-input': '123',
415
- };
69
+ it('should throw error for invalid matrix-asset-uri format', () => {
70
+ const invalidMatrixAssetUri = 'not-valid://canary.uat.matrix.squiz.cloud//abc123';
416
71
  expectToThrowErrorMatchingTypeAndMessage(() => {
417
- jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
418
- }, SchemaValidationError_1.SchemaValidationError, `failed validation: Expected \`123\` (string) in \`#/my-input\` to be of type \`number\``);
72
+ jsonValidationService.validateRenderInput(functionInputSchema, {
73
+ 'matrix-asset': invalidMatrixAssetUri,
74
+ });
75
+ }, SchemaValidationError_1.SchemaValidationError, `failed validation: value "not-valid://canary.uat.matrix.squiz.cloud//abc123" isn't a valid matrix asset uri`);
419
76
  });
420
- it('should throw a SchemaValidationError for invalid input missing properties', () => {
421
- const inputValue = {};
77
+ it('should throw error for invalid matrix-asset-uri type number', () => {
78
+ const invalidMatrixAssetUri = 1234;
422
79
  expectToThrowErrorMatchingTypeAndMessage(() => {
423
- jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
424
- }, SchemaValidationError_1.SchemaValidationError, `failed validation: The required property \`my-input\` is missing at \`#\``);
80
+ jsonValidationService.validateRenderInput(functionInputSchema, {
81
+ 'matrix-asset': invalidMatrixAssetUri,
82
+ });
83
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Expected `1234` (number) in `#/matrix-asset` to be of type `string`');
425
84
  });
426
- it('should throw a SchemaValidationError with a truncated enum value list if there are more than 5 enum options', () => {
85
+ it('should throw error for invalid matrix-asset-uri which does not contain correct number of parts', () => {
86
+ const invalidMatrixAssetUri = 'matrix://';
427
87
  expectToThrowErrorMatchingTypeAndMessage(() => {
428
- jsonValidationService.validateComponentInput({ type: 'object', properties: { enum: { type: 'string', enum: ['a', 'b', 'c', 'd', 'e', 'f', 'g'] } } }, { enum: 'z' });
429
- }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Expected given value `z` in #/enum` to be one of `[a, b, c, d, e, ... 2 more]`');
430
- });
431
- // TODO DEVX-658
432
- it.skip('should throw a SchemaValidationError for invalid input additional properties', () => {
433
- const inputValue = {
434
- 'my-input': 123,
435
- 'my-input-2': 123,
436
- };
437
- expect(() => {
438
- jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
439
- }).toThrowErrorMatchingInlineSnapshot();
88
+ jsonValidationService.validateRenderInput(functionInputSchema, {
89
+ 'matrix-asset': invalidMatrixAssetUri,
90
+ });
91
+ }, SchemaValidationError_1.SchemaValidationError, `failed validation: value "matrix://" isn't a valid matrix asset uri`);
440
92
  });
441
93
  });
442
- });
443
- describe('validateRenderInput', () => {
444
94
  it('should validate a property with type FormattedText as string', () => {
445
95
  const schema = {
446
96
  type: 'object',
@@ -523,29 +173,426 @@ const defaultSchema = {
523
173
  required: ['myProperty'],
524
174
  };
525
175
  function primitiveTypeFixture(title, schema = defaultSchema) {
526
- return (0, arbitraryTypeResolution_1.PrimitiveType)({
176
+ return (0, TypeResolver_1.PrimitiveType)({
527
177
  ...schema,
528
178
  title,
529
179
  });
530
180
  }
531
181
  function resolvableTypeFixture(title, schema = defaultSchema) {
532
- return (0, arbitraryTypeResolution_1.ResolvableType)({
182
+ return (0, TypeResolver_1.ResolvableType)({
533
183
  ...schema,
534
184
  title,
535
185
  });
536
186
  }
537
187
  describe('JsonSchemaService', () => {
188
+ let jsonSchemaService;
189
+ beforeAll(() => {
190
+ const typeResolver = new TypeResolver_1.TypeResolver([primitiveTypes_1.FormattedTextType]);
191
+ jsonSchemaService = new JsonValidationService_1.JSONSchemaService(typeResolver, JsonValidationService_1.ComponentInputMetaSchema);
192
+ });
193
+ describe('validateContentSchema', () => {
194
+ it('should return true for a valid content schema', () => {
195
+ const contentSchema = {
196
+ type: 'object',
197
+ properties: {
198
+ 'my-input': { type: 'number' },
199
+ },
200
+ required: ['my-input'],
201
+ };
202
+ const result = jsonSchemaService.validateInput(contentSchema);
203
+ expect(result).toBe(true);
204
+ });
205
+ it('should return false for an invalid content schema, where the required property is missed from a child object', () => {
206
+ const contentSchema = {
207
+ type: 'object',
208
+ properties: {
209
+ 'my-input': {
210
+ type: 'object',
211
+ properties: {
212
+ 'my-deep-input': { type: 'object' },
213
+ },
214
+ },
215
+ },
216
+ required: ['my-input'],
217
+ };
218
+ expectToThrowErrorMatchingTypeAndMessage(() => {
219
+ jsonSchemaService.validateInput(contentSchema);
220
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: The required property `required` is missing at `#/properties/my-input`');
221
+ });
222
+ it('should throw a SchemaValidationError for an invalid content schema, top level type must be object', () => {
223
+ const contentSchema = {
224
+ type: 'array',
225
+ items: {
226
+ type: 'object',
227
+ properties: {
228
+ 'my-input': { type: 'number' },
229
+ },
230
+ required: ['my-input'],
231
+ },
232
+ };
233
+ expectToThrowErrorMatchingTypeAndMessage(() => {
234
+ jsonSchemaService.validateInput(contentSchema);
235
+ }, SchemaValidationError_1.SchemaValidationError, `failed validation: Expected value at \`#/type\` to be \`object\`, but value given is \`array\``);
236
+ });
237
+ it('should throw a SchemaValidationError for an invalid content schema missing the required property', () => {
238
+ const contentSchema = {
239
+ type: 'object',
240
+ properties: {
241
+ 'my-input': { type: 'number' },
242
+ },
243
+ };
244
+ expectToThrowErrorMatchingTypeAndMessage(() => {
245
+ jsonSchemaService.validateInput(contentSchema);
246
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: The required property `required` is missing at `#`');
247
+ });
248
+ });
249
+ describe('FormattedText input', () => {
250
+ it('should handle type as an array', () => {
251
+ const functionInputSchema = {
252
+ type: 'object',
253
+ properties: {
254
+ 'my-input': { type: ['number', 'string'] },
255
+ },
256
+ required: ['my-input'],
257
+ };
258
+ expect(jsonSchemaService.validateInput({
259
+ 'my-input': 'formattedText',
260
+ }, functionInputSchema)).toEqual(true);
261
+ expect(jsonSchemaService.validateInput({
262
+ 'my-input': 123,
263
+ }, functionInputSchema)).toEqual(true);
264
+ });
265
+ it.failing('should handle type is an array of both string and FormattedText', () => {
266
+ const formattedText = [
267
+ {
268
+ tag: 'p',
269
+ type: 'tag',
270
+ children: [
271
+ { type: 'text', value: 'This is some ' },
272
+ { type: 'text', value: 'Link to asset 12345' },
273
+ { type: 'text', value: ' with an image ' },
274
+ { type: 'text', value: '.' },
275
+ ],
276
+ },
277
+ ];
278
+ const functionInputSchema = {
279
+ type: 'object',
280
+ properties: {
281
+ 'my-input': { type: ['FormattedText', 'string'] },
282
+ },
283
+ required: ['my-input'],
284
+ };
285
+ expect(jsonSchemaService.validateInput({
286
+ 'my-input': formattedText,
287
+ }, functionInputSchema)).toEqual(true);
288
+ expect(jsonSchemaService.validateInput({
289
+ 'my-input': 'hello',
290
+ }, functionInputSchema)).toEqual(true);
291
+ });
292
+ it('should return true if input is formatted text', () => {
293
+ const functionInputSchema = {
294
+ type: 'object',
295
+ properties: {
296
+ 'my-input': { type: 'FormattedText' },
297
+ },
298
+ required: ['my-input'],
299
+ };
300
+ const formattedText = [
301
+ {
302
+ tag: 'p',
303
+ type: 'tag',
304
+ children: [
305
+ { type: 'text', value: 'This is some ' },
306
+ { type: 'text', value: 'Link to asset 12345' },
307
+ { type: 'text', value: ' with an image ' },
308
+ { type: 'text', value: '.' },
309
+ ],
310
+ },
311
+ ];
312
+ const inputValue = {
313
+ 'my-input': formattedText,
314
+ };
315
+ expect(() => jsonSchemaService.validateInput(inputValue, functionInputSchema)).not.toThrow();
316
+ });
317
+ it('should throw an error if the FormattedText input is not formatted text', () => {
318
+ const functionInputSchema = {
319
+ type: 'object',
320
+ properties: {
321
+ 'my-input': { type: 'FormattedText' },
322
+ },
323
+ required: ['my-input'],
324
+ };
325
+ const inputValue = {
326
+ 'my-input': 123,
327
+ };
328
+ expectToThrowErrorMatchingTypeAndMessage(() => {
329
+ jsonSchemaService.validateInput(inputValue, functionInputSchema);
330
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `123` in `#/my-input` does not match any given oneof schema');
331
+ });
332
+ it('should throw an error if the FormattedText input is invalid formatted text', () => {
333
+ const functionInputSchema = {
334
+ type: 'object',
335
+ properties: {
336
+ 'my-input': { type: 'FormattedText' },
337
+ },
338
+ required: ['my-input'],
339
+ };
340
+ const inputValue = {
341
+ 'my-input': {
342
+ something: 'aa',
343
+ },
344
+ };
345
+ expectToThrowErrorMatchingTypeAndMessage(() => {
346
+ jsonSchemaService.validateInput(inputValue, functionInputSchema);
347
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `{"something":"aa"}` in `#/my-input` does not match any given oneof schema');
348
+ });
349
+ it('should throw an error if the FormattedText input is invalid formatted text (deeply nested)', () => {
350
+ const functionInputSchema = {
351
+ type: 'object',
352
+ properties: {
353
+ 'my-input': { type: 'FormattedText' },
354
+ },
355
+ required: ['my-input'],
356
+ };
357
+ const formattedText = [
358
+ {
359
+ tag: 'p',
360
+ type: 'tag',
361
+ children: [
362
+ { type: 'text', value: 'This is some ' },
363
+ { type: 'text', value: 'Link to asset 12345' },
364
+ { type: 'text', value: ' with an image ' },
365
+ { type: 'text', value: 123 },
366
+ { type: 'text', value: '.' },
367
+ ],
368
+ },
369
+ ];
370
+ const inputValue = {
371
+ 'my-input': formattedText,
372
+ };
373
+ expectToThrowErrorMatchingTypeAndMessage(() => {
374
+ jsonSchemaService.validateInput(inputValue, functionInputSchema);
375
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `[{"tag":"p","type":"tag","children":[{"type":"text","value":"This is some "},{"type":"text","value":"Link to asset 12345"},{"type":"text","value":" with an image "},{"type":"text","value":123},{"type":"text","value":"."}]}]` in `#/my-input` does not match any given oneof schema');
376
+ });
377
+ it('should validate an array of formatted texts', () => {
378
+ const formattedText = [
379
+ {
380
+ tag: 'p',
381
+ type: 'tag',
382
+ children: [{ type: 'text', value: 'hello' }],
383
+ },
384
+ ];
385
+ const schema = {
386
+ type: 'object',
387
+ properties: {
388
+ arr: {
389
+ type: 'array',
390
+ items: { type: 'FormattedText' },
391
+ },
392
+ },
393
+ };
394
+ const value = {
395
+ arr: [formattedText],
396
+ };
397
+ expect(jsonSchemaService.validateInput(value, schema)).toEqual(true);
398
+ });
399
+ it('should throw an error if the FormattedText input is invalid formatted text (deeply, deeply nested)', () => {
400
+ const formattedText = [
401
+ {
402
+ tag: 'p',
403
+ type: 'tag',
404
+ children: [{ type: 'text', value: 'hello' }],
405
+ },
406
+ ];
407
+ const inputValue = {
408
+ 'my-input': formattedText,
409
+ deep: {
410
+ arr: [
411
+ {
412
+ prop: formattedText,
413
+ formattedTextArray: [formattedText, formattedText, { bad: 'data' }],
414
+ },
415
+ ],
416
+ },
417
+ };
418
+ const functionInputSchema = {
419
+ type: 'object',
420
+ properties: {
421
+ 'my-input': { type: 'FormattedText' },
422
+ deep: {
423
+ type: 'object',
424
+ properties: {
425
+ arr: {
426
+ type: 'array',
427
+ items: {
428
+ type: 'object',
429
+ required: ['prop', 'formattedTextArray'],
430
+ properties: {
431
+ prop: 'FormattedText',
432
+ formattedTextArray: {
433
+ type: 'array',
434
+ items: {
435
+ type: 'FormattedText',
436
+ },
437
+ },
438
+ },
439
+ },
440
+ },
441
+ },
442
+ required: ['arr'],
443
+ },
444
+ },
445
+ required: ['my-input', 'deep'],
446
+ };
447
+ expectToThrowErrorMatchingTypeAndMessage(() => {
448
+ jsonSchemaService.validateInput(inputValue, functionInputSchema);
449
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `{"bad":"data"}` in `#/deep/arr/0/formattedTextArray/2` does not match any given oneof schema');
450
+ });
451
+ it('should validate a FormattedText value when the schema is a $ref', async () => {
452
+ const formattedText = [
453
+ {
454
+ tag: 'p',
455
+ type: 'tag',
456
+ children: [{ type: 'text', value: 'hello' }],
457
+ },
458
+ ];
459
+ const schema = {
460
+ type: 'object',
461
+ properties: {
462
+ 'my-input': { $ref: '#/definitions/FormattedText' },
463
+ },
464
+ definitions: {
465
+ FormattedText: { type: 'FormattedText' },
466
+ },
467
+ required: ['my-input'],
468
+ };
469
+ const value = {
470
+ 'my-input': formattedText,
471
+ };
472
+ expect(jsonSchemaService.validateInput(value, schema)).toEqual(true);
473
+ });
474
+ it('should error when a FormattedText value is invalid when the schema is a $ref', async () => {
475
+ const schema = {
476
+ type: 'object',
477
+ properties: {
478
+ 'my-input': { $ref: '#/definitions/FormattedText' },
479
+ },
480
+ definitions: {
481
+ FormattedText: { type: 'FormattedText' },
482
+ },
483
+ required: ['my-input'],
484
+ };
485
+ const value = {
486
+ 'my-input': { bad: 'data' },
487
+ };
488
+ expectToThrowErrorMatchingTypeAndMessage(() => {
489
+ jsonSchemaService.validateInput(value, schema);
490
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `{"bad":"data"}` in `#/my-input` does not match any given oneof schema');
491
+ });
492
+ it('should validate a FormattedText value when the schema is a $ref to a $ref', async () => {
493
+ const formattedText = [
494
+ {
495
+ tag: 'p',
496
+ type: 'tag',
497
+ children: [{ type: 'text', value: 'hello' }],
498
+ },
499
+ ];
500
+ const schema = {
501
+ type: 'object',
502
+ properties: {
503
+ 'my-input': { $ref: '#/definitions/FormattedText' },
504
+ },
505
+ definitions: {
506
+ FormattedText: { $ref: '#/definitions/FormattedText2' },
507
+ FormattedText2: { type: 'FormattedText' },
508
+ },
509
+ required: ['my-input'],
510
+ };
511
+ const value = {
512
+ 'my-input': formattedText,
513
+ };
514
+ expect(jsonSchemaService.validateInput(value, schema)).toEqual(true);
515
+ });
516
+ it('should validate a FormattedText value when the schema is in an if/then/else', async () => {
517
+ const formattedText = [
518
+ {
519
+ tag: 'p',
520
+ type: 'tag',
521
+ children: [{ type: 'text', value: 'hello' }],
522
+ },
523
+ ];
524
+ const schema = {
525
+ type: 'object',
526
+ properties: {
527
+ 'my-input': {
528
+ if: { type: 'string' },
529
+ then: { type: 'string' },
530
+ else: { type: 'FormattedText' },
531
+ },
532
+ },
533
+ required: ['my-input'],
534
+ };
535
+ const value = {
536
+ 'my-input': formattedText,
537
+ };
538
+ expect(jsonSchemaService.validateInput(value, schema)).toEqual(true);
539
+ });
540
+ });
541
+ describe('standard inputs', () => {
542
+ const functionInputSchema = {
543
+ type: 'object',
544
+ properties: {
545
+ 'my-input': { type: 'number' },
546
+ },
547
+ required: ['my-input'],
548
+ };
549
+ it('should return true for valid input values', () => {
550
+ const inputValue = {
551
+ 'my-input': 123,
552
+ };
553
+ const result = jsonSchemaService.validateInput(inputValue, functionInputSchema);
554
+ expect(result).toBe(true);
555
+ });
556
+ it('should throw a SchemaValidationError for invalid input type', () => {
557
+ const inputValue = {
558
+ 'my-input': '123',
559
+ };
560
+ expectToThrowErrorMatchingTypeAndMessage(() => {
561
+ jsonSchemaService.validateInput(inputValue, functionInputSchema);
562
+ }, SchemaValidationError_1.SchemaValidationError, `failed validation: Expected \`123\` (string) in \`#/my-input\` to be of type \`number\``);
563
+ });
564
+ it('should throw a SchemaValidationError for invalid input missing properties', () => {
565
+ const inputValue = {};
566
+ expectToThrowErrorMatchingTypeAndMessage(() => {
567
+ jsonSchemaService.validateInput(inputValue, functionInputSchema);
568
+ }, SchemaValidationError_1.SchemaValidationError, `failed validation: The required property \`my-input\` is missing at \`#\``);
569
+ });
570
+ it('should throw a SchemaValidationError with a truncated enum value list if there are more than 5 enum options', () => {
571
+ expectToThrowErrorMatchingTypeAndMessage(() => {
572
+ jsonSchemaService.validateInput({ enum: 'z' }, { type: 'object', properties: { enum: { type: 'string', enum: ['a', 'b', 'c', 'd', 'e', 'f', 'g'] } } });
573
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Expected given value `z` in #/enum` to be one of `[a, b, c, d, e, ... 2 more]`');
574
+ });
575
+ // TODO DEVX-658
576
+ it.skip('should throw a SchemaValidationError for invalid input additional properties', () => {
577
+ const inputValue = {
578
+ 'my-input': 123,
579
+ 'my-input-2': 123,
580
+ };
581
+ expect(() => {
582
+ jsonSchemaService.validateInput(inputValue, functionInputSchema);
583
+ }).toThrowErrorMatchingInlineSnapshot();
584
+ });
585
+ });
538
586
  describe('validateInput', () => {
539
587
  it.each([String('123'), Number(123), [123]])('should validate any primitive type with its resolvable type %s', (propertyValue) => {
540
588
  const primitiveSchema = primitiveTypeFixture('MyPrimitive', { type: 'string' });
541
- const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new arbitraryTypeResolution_1.TypeResolver({
542
- MyPrimitive: primitiveSchema,
543
- }, {
544
- MyResolvableNumber: resolvableTypeFixture('MyResolvableNumber', { type: 'number' }),
545
- MyResolvableArray: resolvableTypeFixture('MyResolvableArray', { type: 'array' }),
546
- }, {
589
+ const MyResolvableNumber = resolvableTypeFixture('MyResolvableNumber', { type: 'number' });
590
+ const MyResolvableArray = resolvableTypeFixture('MyResolvableArray', { type: 'array' });
591
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new TypeResolver_1.TypeResolver([primitiveSchema], [MyResolvableNumber, MyResolvableArray], {
547
592
  MyPrimitive: {
593
+ // @ts-expect-error - fixture is unknown but we know the actual shape
548
594
  MyResolvableNumber: (value) => value.toString(),
595
+ // @ts-expect-error - fixture is unknown but we know the actual shape
549
596
  MyResolvableArray: (value) => value.join(''),
550
597
  },
551
598
  }), JsonValidationService_1.ComponentInputMetaSchema);
@@ -553,14 +600,13 @@ describe('JsonSchemaService', () => {
553
600
  });
554
601
  it('should error when a primitive type is provided a value that cannot be resolved by its resolvable types', () => {
555
602
  const primitiveSchema = primitiveTypeFixture('MyPrimitive', { type: 'string' });
556
- const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new arbitraryTypeResolution_1.TypeResolver({
557
- MyPrimitive: primitiveSchema,
558
- }, {
559
- MyResolvableNumber: resolvableTypeFixture('MyResolvableNumber', { type: 'number' }),
560
- MyResolvableArray: resolvableTypeFixture('MyResolvableArray', { type: 'array' }),
561
- }, {
603
+ const MyResolvableNumber = resolvableTypeFixture('MyResolvableNumber', { type: 'number' });
604
+ const MyResolvableArray = resolvableTypeFixture('MyResolvableArray', { type: 'array' });
605
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new TypeResolver_1.TypeResolver([primitiveSchema], [MyResolvableNumber, MyResolvableArray], {
562
606
  MyPrimitive: {
607
+ // @ts-expect-error - fixture is unknown but we know the actual shape
563
608
  MyResolvableNumber: (value) => value.toString(),
609
+ // @ts-expect-error - fixture is unknown but we know the actual shape
564
610
  MyResolvableArray: (value) => value.join(''),
565
611
  },
566
612
  }), JsonValidationService_1.ComponentInputMetaSchema);
@@ -570,14 +616,13 @@ describe('JsonSchemaService', () => {
570
616
  });
571
617
  it.each([String('123'), Number(123), [123]])('should validate a primitive type when defined as a ref with resolvable value %s', (propertyValue) => {
572
618
  const primitiveSchema = primitiveTypeFixture('MyPrimitive', { type: 'string' });
573
- const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new arbitraryTypeResolution_1.TypeResolver({
574
- MyPrimitive: primitiveSchema,
575
- }, {
576
- MyResolvableNumber: resolvableTypeFixture('MyResolvableNumber', { type: 'number' }),
577
- MyResolvableArray: resolvableTypeFixture('MyResolvableArray', { type: 'array' }),
578
- }, {
619
+ const MyResolvableNumber = resolvableTypeFixture('MyResolvableNumber', { type: 'number' });
620
+ const MyResolvableArray = resolvableTypeFixture('MyResolvableArray', { type: 'array' });
621
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new TypeResolver_1.TypeResolver([primitiveSchema], [MyResolvableNumber, MyResolvableArray], {
579
622
  MyPrimitive: {
623
+ // @ts-expect-error - fixture is unknown but we know the actual shape
580
624
  MyResolvableNumber: (value) => value.toString(),
625
+ // @ts-expect-error - fixture is unknown but we know the actual shape
581
626
  MyResolvableArray: (value) => value.join(''),
582
627
  },
583
628
  }), JsonValidationService_1.ComponentInputMetaSchema);
@@ -589,13 +634,11 @@ describe('JsonSchemaService', () => {
589
634
  });
590
635
  it('should not validate on a primitive type against a resolvable type when a resolver is not defined', () => {
591
636
  const primitiveSchema = primitiveTypeFixture('MyPrimitive', { type: 'string' });
592
- const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new arbitraryTypeResolution_1.TypeResolver({
593
- MyPrimitive: primitiveSchema,
594
- }, {
595
- MyResolvableNumber: resolvableTypeFixture('MyResolvableNumber', { type: 'number' }),
596
- MyResolvableArray: resolvableTypeFixture('MyResolvableArray', { type: 'array' }),
597
- }, {
637
+ const MyResolvableNumber = resolvableTypeFixture('MyResolvableNumber', { type: 'number' });
638
+ const MyResolvableArray = resolvableTypeFixture('MyResolvableArray', { type: 'array' });
639
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new TypeResolver_1.TypeResolver([primitiveSchema], [MyResolvableNumber, MyResolvableArray], {
598
640
  MyPrimitive: {
641
+ // @ts-expect-error - fixture is unknown but we know the actual shape
599
642
  MyResolvableNumber: (value) => value.toString(),
600
643
  },
601
644
  }), JsonValidationService_1.ComponentInputMetaSchema);
@@ -605,24 +648,24 @@ describe('JsonSchemaService', () => {
605
648
  });
606
649
  it('should validate a primitive type against similar but different resolvable types', () => {
607
650
  const primitiveSchema = primitiveTypeFixture('MyPrimitive', { type: 'string' });
608
- const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new arbitraryTypeResolution_1.TypeResolver({
609
- MyPrimitive: primitiveSchema,
610
- }, {
611
- MyResolvableSrcNumber: resolvableTypeFixture('MyResolvableSrcNumber', {
651
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new TypeResolver_1.TypeResolver([primitiveSchema], [
652
+ resolvableTypeFixture('MyResolvableSrcNumber', {
612
653
  type: 'object',
613
654
  properties: {
614
655
  src: { type: 'number' },
615
656
  },
616
657
  }),
617
- MyResolvableSrcString: resolvableTypeFixture('MyResolvableSrcString', {
658
+ resolvableTypeFixture('MyResolvableSrcString', {
618
659
  type: 'object',
619
660
  properties: {
620
661
  src: { type: 'string' },
621
662
  },
622
663
  }),
623
- }, {
664
+ ], {
624
665
  MyPrimitive: {
666
+ // @ts-expect-error - fixture is unknown but we know the actual shape
625
667
  MyResolvableSrcNumber: (value) => value.src.toString(),
668
+ // @ts-expect-error - fixture is unknown but we know the actual shape
626
669
  MyResolvableSrcString: (value) => value.src,
627
670
  },
628
671
  }), JsonValidationService_1.ComponentInputMetaSchema);
@@ -641,14 +684,14 @@ describe('JsonSchemaService', () => {
641
684
  describe('resolveInput', () => {
642
685
  it.each([String('123'), Number(123), [123]])('should resolve a primitive type from its resolvable type %s', async (resolvableValue) => {
643
686
  const primitiveSchema = primitiveTypeFixture('MyPrimitive', { type: 'string' });
644
- const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new arbitraryTypeResolution_1.TypeResolver({
645
- MyPrimitive: primitiveSchema,
646
- }, {
647
- MyResolvableNumber: resolvableTypeFixture('MyResolvableNumber', { type: 'number' }),
648
- MyResolvableArray: resolvableTypeFixture('MyResolvableArray', { type: 'array' }),
649
- }, {
687
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new TypeResolver_1.TypeResolver([primitiveSchema], [
688
+ resolvableTypeFixture('MyResolvableNumber', { type: 'number' }),
689
+ resolvableTypeFixture('MyResolvableArray', { type: 'array' }),
690
+ ], {
650
691
  MyPrimitive: {
692
+ // @ts-expect-error - fixture is unknown but we know the actual shape
651
693
  MyResolvableNumber: (value) => value.toString(),
694
+ // @ts-expect-error - fixture is unknown but we know the actual shape
652
695
  MyResolvableArray: (value) => value.join(''),
653
696
  },
654
697
  }), JsonValidationService_1.ComponentInputMetaSchema);
@@ -659,20 +702,20 @@ describe('JsonSchemaService', () => {
659
702
  [{ src: 1132 }, '1132'],
660
703
  ])('should resolve a resolvable type %s against the correct resolver to %s', async (resolvableValue, output) => {
661
704
  const primitiveSchema = primitiveTypeFixture('MyPrimitive', { type: 'string' });
662
- const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new arbitraryTypeResolution_1.TypeResolver({
663
- MyPrimitive: primitiveSchema,
664
- }, {
665
- MyResolvableSrcString: resolvableTypeFixture('MyResolvableSrcString', {
705
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(new TypeResolver_1.TypeResolver([primitiveSchema], [
706
+ resolvableTypeFixture('MyResolvableSrcString', {
666
707
  type: 'object',
667
708
  properties: { src: { type: 'string' } },
668
709
  }),
669
- MyResolvableSrcNumber: resolvableTypeFixture('MyResolvableSrcNumber', {
710
+ resolvableTypeFixture('MyResolvableSrcNumber', {
670
711
  type: 'object',
671
712
  properties: { src: { type: 'number' } },
672
713
  }),
673
- }, {
714
+ ], {
674
715
  MyPrimitive: {
716
+ // @ts-expect-error - fixture is unknown but we know the actual shape
675
717
  MyResolvableSrcNumber: (value) => value.src.toString(),
718
+ // @ts-expect-error - fixture is unknown but we know the actual shape
676
719
  MyResolvableSrcString: (value) => value.src,
677
720
  },
678
721
  }), JsonValidationService_1.ComponentInputMetaSchema);