@squiz/dx-json-schema-lib 1.34.1-alpha.0 → 1.34.1-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,36 +2,36 @@
2
2
  1 info using npm@9.5.0
3
3
  2 info using node@v18.15.0
4
4
  3 timing npm:load:whichnode Completed in 1ms
5
- 4 timing config:load:defaults Completed in 3ms
5
+ 4 timing config:load:defaults Completed in 2ms
6
6
  5 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 0ms
7
7
  6 timing config:load:builtin Completed in 0ms
8
8
  7 timing config:load:cli Completed in 2ms
9
- 8 timing config:load:env Completed in 2ms
9
+ 8 timing config:load:env Completed in 1ms
10
10
  9 info found workspace root at /builds/developer-experience/cmp
11
11
  10 timing config:load:file:/builds/developer-experience/cmp/.npmrc Completed in 0ms
12
- 11 timing config:load:project Completed in 21ms
12
+ 11 timing config:load:project Completed in 23ms
13
13
  12 timing config:load:file:/root/.npmrc Completed in 1ms
14
- 13 timing config:load:user Completed in 2ms
14
+ 13 timing config:load:user Completed in 1ms
15
15
  14 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
16
16
  15 timing config:load:global Completed in 0ms
17
- 16 timing config:load:setEnvs Completed in 1ms
18
- 17 timing config:load Completed in 31ms
19
- 18 timing npm:load:configload Completed in 31ms
20
- 19 timing npm:load:mkdirpcache Completed in 1ms
17
+ 16 timing config:load:setEnvs Completed in 2ms
18
+ 17 timing config:load Completed in 33ms
19
+ 18 timing npm:load:configload Completed in 33ms
20
+ 19 timing npm:load:mkdirpcache Completed in 0ms
21
21
  20 timing npm:load:mkdirplogs Completed in 0ms
22
22
  21 verbose title npm run compile
23
23
  22 verbose argv "run" "compile" "--"
24
- 23 timing npm:load:setTitle Completed in 1ms
25
- 24 timing config:load:flatten Completed in 5ms
26
- 25 timing npm:load:display Completed in 6ms
27
- 26 verbose logfile logs-max:10 dir:/builds/developer-experience/cmp/packages/dx-json-schema-lib/.npm/_logs/2023-05-17T04_23_12_814Z-
28
- 27 verbose logfile /builds/developer-experience/cmp/packages/dx-json-schema-lib/.npm/_logs/2023-05-17T04_23_12_814Z-debug-0.log
29
- 28 timing npm:load:logFile Completed in 18ms
24
+ 23 timing npm:load:setTitle Completed in 2ms
25
+ 24 timing config:load:flatten Completed in 4ms
26
+ 25 timing npm:load:display Completed in 5ms
27
+ 26 verbose logfile logs-max:10 dir:/builds/developer-experience/cmp/packages/dx-json-schema-lib/.npm/_logs/2023-05-18T22_22_20_519Z-
28
+ 27 verbose logfile /builds/developer-experience/cmp/packages/dx-json-schema-lib/.npm/_logs/2023-05-18T22_22_20_519Z-debug-0.log
29
+ 28 timing npm:load:logFile Completed in 3ms
30
30
  29 timing npm:load:timers Completed in 0ms
31
- 30 timing npm:load:configScope Completed in 0ms
32
- 31 timing npm:load Completed in 59ms
31
+ 30 timing npm:load:configScope Completed in 1ms
32
+ 31 timing npm:load Completed in 46ms
33
33
  32 silly logfile done cleaning log files
34
- 33 timing command:run Completed in 8690ms
34
+ 33 timing command:run Completed in 7598ms
35
35
  34 verbose exit 0
36
- 35 timing npm Completed in 8762ms
36
+ 35 timing npm Completed in 7656ms
37
37
  36 info ok
@@ -10,6 +10,8 @@ const validComponentJson_json_1 = __importDefault(require("./manifest/v1/__test_
10
10
  const inputStringWithFormat_json_1 = __importDefault(require("./manifest/v1/__test__/schemas/inputStringWithFormat.json"));
11
11
  const TypeResolver_1 = require("./jsonTypeResolution/TypeResolver");
12
12
  const primitiveTypes_1 = require("./primitiveTypes");
13
+ const TypeResolverBuilder_1 = require("./jsonTypeResolution/TypeResolverBuilder");
14
+ const resolvableTypes_1 = require("./resolvableTypes");
13
15
  function expectToThrowErrorMatchingTypeAndMessage(
14
16
  // eslint-disable-next-line @typescript-eslint/ban-types
15
17
  received,
@@ -111,21 +113,30 @@ describe('JsonValidationService', () => {
111
113
  jsonValidationService.validateRenderInput(functionInputSchema, {
112
114
  'matrix-asset': invalidMatrixAssetUri,
113
115
  });
114
- }, SchemaValidationError_1.SchemaValidationError, `failed validation: matrix asset uri "not-valid://canary uat matrix.squiz.cloud//abc123" isn't a valid matrix asset uri`, {
115
- '#/matrix-asset': {
116
- assetId: {
117
- data: { expected: /^\d+(?::.+)?$/, received: '/abc123' },
118
- message: 'Matrix Asset Id has invalid format, must match /^d+(?::.+)?$/',
119
- },
120
- identifier: {
121
- data: { expected: /^[a-zA-Z0-9.-]+$/, received: 'canary uat matrix.squiz.cloud' },
122
- message: 'Matrix Identifier has invalid format, must match /^[a-zA-Z0-9.-]+$/',
123
- },
124
- scheme: {
125
- data: { expected: 'matrix-asset', received: 'not-valid' },
126
- message: 'Uri scheme is invalid, must match "matrix-asset"',
116
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value matrix-asset-uri (not-valid://canary uat matrix.squiz.cloud//abc123) in `#/matrix-asset` is not a valid matrix asset uri', {
117
+ '#/matrix-asset': [
118
+ {
119
+ data: {
120
+ errors: {
121
+ assetId: {
122
+ data: { expected: /^\d+(?::.+)?$/, received: '/abc123' },
123
+ message: 'Matrix Asset Id has invalid format, must match /^d+(?::.+)?$/',
124
+ },
125
+ identifier: {
126
+ data: { expected: /^[a-zA-Z0-9.-]+$/, received: 'canary uat matrix.squiz.cloud' },
127
+ message: 'Matrix Identifier has invalid format, must match /^[a-zA-Z0-9.-]+$/',
128
+ },
129
+ scheme: {
130
+ data: { expected: 'matrix-asset', received: 'not-valid' },
131
+ message: 'Uri scheme is invalid, must match "matrix-asset"',
132
+ },
133
+ },
134
+ pointer: '#/matrix-asset',
135
+ value: 'not-valid://canary uat matrix.squiz.cloud//abc123',
136
+ },
137
+ message: 'Value matrix-asset-uri (not-valid://canary uat matrix.squiz.cloud//abc123) in `#/matrix-asset` is not a valid matrix asset uri',
127
138
  },
128
- },
139
+ ],
129
140
  });
130
141
  });
131
142
  it('should throw error for invalid matrix-asset-uri type number', () => {
@@ -149,21 +160,30 @@ describe('JsonValidationService', () => {
149
160
  jsonValidationService.validateRenderInput(functionInputSchema, {
150
161
  'matrix-asset': invalidMatrixAssetUri,
151
162
  });
152
- }, SchemaValidationError_1.SchemaValidationError, `failed validation: matrix asset uri "matrix://" isn't a valid matrix asset uri`, {
153
- '#/matrix-asset': {
154
- assetId: {
155
- data: { expected: /^\d+(?::.+)?$/, received: '' },
156
- message: 'Matrix Asset Id has invalid format, must match /^d+(?::.+)?$/',
157
- },
158
- identifier: {
159
- data: { expected: /^[a-zA-Z0-9.-]+$/, received: '' },
160
- message: 'Matrix Identifier has invalid format, must match /^[a-zA-Z0-9.-]+$/',
161
- },
162
- scheme: {
163
- data: { expected: 'matrix-asset', received: 'matrix' },
164
- message: 'Uri scheme is invalid, must match "matrix-asset"',
163
+ }, SchemaValidationError_1.SchemaValidationError, 'failed validation: Value matrix-asset-uri (matrix://) in `#/matrix-asset` is not a valid matrix asset uri', {
164
+ '#/matrix-asset': [
165
+ {
166
+ data: {
167
+ errors: {
168
+ assetId: {
169
+ data: { expected: /^\d+(?::.+)?$/, received: '' },
170
+ message: 'Matrix Asset Id has invalid format, must match /^d+(?::.+)?$/',
171
+ },
172
+ identifier: {
173
+ data: { expected: /^[a-zA-Z0-9.-]+$/, received: '' },
174
+ message: 'Matrix Identifier has invalid format, must match /^[a-zA-Z0-9.-]+$/',
175
+ },
176
+ scheme: {
177
+ data: { expected: 'matrix-asset', received: 'matrix' },
178
+ message: 'Uri scheme is invalid, must match "matrix-asset"',
179
+ },
180
+ },
181
+ pointer: '#/matrix-asset',
182
+ value: 'matrix://',
183
+ },
184
+ message: 'Value matrix-asset-uri (matrix://) in `#/matrix-asset` is not a valid matrix asset uri',
165
185
  },
166
- },
186
+ ],
167
187
  });
168
188
  });
169
189
  });
@@ -1048,4 +1068,479 @@ describe('JsonSchemaService', () => {
1048
1068
  });
1049
1069
  });
1050
1070
  });
1071
+ describe('JSONSchemaService - validation', () => {
1072
+ const typeResolver = TypeResolverBuilder_1.TypeResolverBuilder.new()
1073
+ .addPrimitive(primitiveTypes_1.SquizImageType)
1074
+ .addPrimitive(primitiveTypes_1.SquizLinkType)
1075
+ .addPrimitive(primitiveTypes_1.FormattedTextType)
1076
+ .build();
1077
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(typeResolver, JsonValidationService_1.ComponentInputMetaSchema);
1078
+ it('should validate a schema with all the squiz primitive types', () => {
1079
+ const schema = {
1080
+ type: 'object',
1081
+ properties: {
1082
+ image: { type: 'SquizImage' },
1083
+ link: { type: 'SquizLink' },
1084
+ text: { type: 'FormattedText' },
1085
+ },
1086
+ required: ['image', 'link', 'text'],
1087
+ };
1088
+ const formattedText = [
1089
+ {
1090
+ tag: 'p',
1091
+ type: 'tag',
1092
+ children: [{ type: 'text', value: 'hello' }],
1093
+ },
1094
+ ];
1095
+ const input = {
1096
+ image: {
1097
+ name: 'test-image.jpeg',
1098
+ imageVariations: {
1099
+ original: {
1100
+ aspectRatio: '1:1',
1101
+ height: 100,
1102
+ width: 100,
1103
+ url: 'https://www.squiz.net',
1104
+ byteSize: 100,
1105
+ mimeType: 'image/jpeg',
1106
+ sha1Hash: '123',
1107
+ },
1108
+ },
1109
+ },
1110
+ link: {
1111
+ name: 'test-link',
1112
+ url: 'https://www.squiz.net',
1113
+ target: '_blank',
1114
+ },
1115
+ text: formattedText,
1116
+ };
1117
+ const result = jsonSchemaService.validateInput(input, schema);
1118
+ expect(result).toEqual(true);
1119
+ });
1120
+ it('should validate a schema with all the squiz primitive types and matrix-asset-uri format', () => {
1121
+ const schema = {
1122
+ type: 'object',
1123
+ properties: {
1124
+ image: { type: 'SquizImage' },
1125
+ link: { type: 'SquizLink' },
1126
+ text: { type: 'FormattedText' },
1127
+ asset: {
1128
+ type: 'string',
1129
+ format: 'matrix-asset-uri',
1130
+ },
1131
+ },
1132
+ required: ['image', 'link', 'text', 'asset'],
1133
+ };
1134
+ const formattedText = [
1135
+ {
1136
+ tag: 'p',
1137
+ type: 'tag',
1138
+ children: [{ type: 'text', value: 'hello' }],
1139
+ },
1140
+ ];
1141
+ const input = {
1142
+ image: {
1143
+ name: 'test-image.jpeg',
1144
+ imageVariations: {
1145
+ original: {
1146
+ aspectRatio: '1:1',
1147
+ height: 100,
1148
+ width: 100,
1149
+ url: 'https://www.squiz.net',
1150
+ byteSize: 100,
1151
+ mimeType: 'image/jpeg',
1152
+ sha1Hash: '123',
1153
+ },
1154
+ },
1155
+ },
1156
+ link: {
1157
+ name: 'test-link',
1158
+ url: 'https://www.squiz.net',
1159
+ target: '_blank',
1160
+ },
1161
+ text: formattedText,
1162
+ asset: 'matrix-asset://identifier/123',
1163
+ };
1164
+ const result = jsonSchemaService.validateInput(input, schema);
1165
+ expect(result).toEqual(true);
1166
+ });
1167
+ it('should catch validation errors when there is a schema with all the squiz primitive types', () => {
1168
+ const schema = {
1169
+ type: 'object',
1170
+ properties: {
1171
+ image: { type: 'SquizImage' },
1172
+ link: { type: 'SquizLink' },
1173
+ text: { type: 'FormattedText' },
1174
+ },
1175
+ required: ['image', 'link', 'text'],
1176
+ };
1177
+ const formattedText = [
1178
+ //@ts-expect-error - wrong type
1179
+ {
1180
+ children: [{ type: 'text', value: 'hello' }],
1181
+ },
1182
+ ];
1183
+ const input = {
1184
+ image: {
1185
+ name: 'test-image.jpeg',
1186
+ imageVariations: {
1187
+ //@ts-expect-error - wrong type
1188
+ original: {
1189
+ width: 100,
1190
+ url: 'https://www.squiz.net',
1191
+ byteSize: 100,
1192
+ mimeType: 'image/jpeg',
1193
+ sha1Hash: '123',
1194
+ },
1195
+ },
1196
+ },
1197
+ //@ts-expect-error - wrong type
1198
+ link: {
1199
+ name: 'test-link',
1200
+ target: '_blank',
1201
+ },
1202
+ text: formattedText,
1203
+ };
1204
+ expectToThrowErrorMatchingTypeAndMessage(() => jsonSchemaService.validateInput(input, schema), SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `{"name":"test-image.jpeg","imageVariations":{"original":{"width":100,"url":"https://www.squiz.net","byteSize":100,"mimeType":"image/jpeg","sha1Hash":"123"}}}` in `#/image` does not match any given oneof schema,\nValue `{"name":"test-link","target":"_blank"}` in `#/link` does not match any given oneof schema,\nValue `[{"children":[{"type":"text","value":"hello"}]}]` in `#/text` does not match any given oneof schema', {
1205
+ '#/image': [
1206
+ {
1207
+ data: {
1208
+ errors: [
1209
+ {
1210
+ code: 'required-property-error',
1211
+ data: { key: 'height', pointer: '#/image/imageVariations/original' },
1212
+ message: 'The required property `height` is missing at `#/image/imageVariations/original`',
1213
+ name: 'RequiredPropertyError',
1214
+ type: 'error',
1215
+ },
1216
+ {
1217
+ code: 'required-property-error',
1218
+ data: { key: 'aspectRatio', pointer: '#/image/imageVariations/original' },
1219
+ message: 'The required property `aspectRatio` is missing at `#/image/imageVariations/original`',
1220
+ name: 'RequiredPropertyError',
1221
+ type: 'error',
1222
+ },
1223
+ ],
1224
+ oneOf: [{ $ref: 'SquizImage.json' }],
1225
+ pointer: '#/image',
1226
+ value: '{"name":"test-image.jpeg","imageVariations":{"original":{"width":100,"url":"https://www.squiz.net","byteSize":100,"mimeType":"image/jpeg","sha1Hash":"123"}}}',
1227
+ },
1228
+ message: 'Value `{"name":"test-image.jpeg","imageVariations":{"original":{"width":100,"url":"https://www.squiz.net","byteSize":100,"mimeType":"image/jpeg","sha1Hash":"123"}}}` in `#/image` does not match any given oneof schema',
1229
+ },
1230
+ ],
1231
+ '#/link': [
1232
+ {
1233
+ data: {
1234
+ errors: [
1235
+ {
1236
+ code: 'required-property-error',
1237
+ data: { key: 'url', pointer: '#/link' },
1238
+ message: 'The required property `url` is missing at `#/link`',
1239
+ name: 'RequiredPropertyError',
1240
+ type: 'error',
1241
+ },
1242
+ ],
1243
+ oneOf: [{ $ref: 'SquizLink.json' }],
1244
+ pointer: '#/link',
1245
+ value: '{"name":"test-link","target":"_blank"}',
1246
+ },
1247
+ message: 'Value `{"name":"test-link","target":"_blank"}` in `#/link` does not match any given oneof schema',
1248
+ },
1249
+ ],
1250
+ '#/text': [
1251
+ {
1252
+ data: {
1253
+ errors: [
1254
+ {
1255
+ code: 'any-of-error',
1256
+ data: {
1257
+ anyOf: [
1258
+ { $ref: '#/definitions/HigherOrderFormattedNodes' },
1259
+ { $ref: '#/definitions/BaseFormattedNodes' },
1260
+ ],
1261
+ pointer: '#/text/0',
1262
+ value: { children: [{ type: 'text', value: 'hello' }] },
1263
+ },
1264
+ message: 'Object at `#/text/0` does not match any schema',
1265
+ name: 'AnyOfError',
1266
+ type: 'error',
1267
+ },
1268
+ ],
1269
+ oneOf: [{ $ref: 'FormattedText.json' }],
1270
+ pointer: '#/text',
1271
+ value: '[{"children":[{"type":"text","value":"hello"}]}]',
1272
+ },
1273
+ message: 'Value `[{"children":[{"type":"text","value":"hello"}]}]` in `#/text` does not match any given oneof schema',
1274
+ },
1275
+ ],
1276
+ });
1277
+ });
1278
+ it('should catch validation errors when invalid matrix-asset-uri is provided with invalid other squiz primitive types ', () => {
1279
+ const schema = {
1280
+ type: 'object',
1281
+ properties: {
1282
+ image: { type: 'SquizImage' },
1283
+ link: { type: 'SquizLink' },
1284
+ text: { type: 'FormattedText' },
1285
+ asset: {
1286
+ type: 'string',
1287
+ format: 'matrix-asset-uri',
1288
+ },
1289
+ },
1290
+ required: ['image', 'link', 'text', 'asset'],
1291
+ };
1292
+ const formattedText = [
1293
+ //@ts-expect-error - wrong type
1294
+ {
1295
+ children: [{ type: 'text', value: 'hello' }],
1296
+ },
1297
+ ];
1298
+ const input = {
1299
+ image: {
1300
+ name: 'test-image.jpeg',
1301
+ imageVariations: {
1302
+ //@ts-expect-error - wrong type
1303
+ original: {
1304
+ width: 100,
1305
+ url: 'https://www.squiz.net',
1306
+ byteSize: 100,
1307
+ mimeType: 'image/jpeg',
1308
+ sha1Hash: '123',
1309
+ },
1310
+ },
1311
+ },
1312
+ //@ts-expect-error - wrong type
1313
+ link: {
1314
+ name: 'test-link',
1315
+ target: '_blank',
1316
+ },
1317
+ text: formattedText,
1318
+ // @ts-expect-error - wrong type
1319
+ asset: 'matrix://123',
1320
+ };
1321
+ expectToThrowErrorMatchingTypeAndMessage(() => jsonSchemaService.validateInput(input, schema), SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `{"name":"test-image.jpeg","imageVariations":{"original":{"width":100,"url":"https://www.squiz.net","byteSize":100,"mimeType":"image/jpeg","sha1Hash":"123"}}}` in `#/image` does not match any given oneof schema,\nValue `{"name":"test-link","target":"_blank"}` in `#/link` does not match any given oneof schema,\nValue `[{"children":[{"type":"text","value":"hello"}]}]` in `#/text` does not match any given oneof schema,\nValue matrix-asset-uri (matrix://123) in `#/asset` is not a valid matrix asset uri', {
1322
+ '#/asset': [
1323
+ {
1324
+ data: {
1325
+ errors: {
1326
+ assetId: {
1327
+ data: { expected: /^\d+(?::.+)?$/, received: '' },
1328
+ message: 'Matrix Asset Id has invalid format, must match /^d+(?::.+)?$/',
1329
+ },
1330
+ scheme: {
1331
+ data: { expected: 'matrix-asset', received: 'matrix' },
1332
+ message: 'Uri scheme is invalid, must match "matrix-asset"',
1333
+ },
1334
+ },
1335
+ pointer: '#/asset',
1336
+ value: 'matrix://123',
1337
+ },
1338
+ message: 'Value matrix-asset-uri (matrix://123) in `#/asset` is not a valid matrix asset uri',
1339
+ },
1340
+ ],
1341
+ '#/image': [
1342
+ {
1343
+ data: {
1344
+ errors: [
1345
+ {
1346
+ code: 'required-property-error',
1347
+ data: { key: 'height', pointer: '#/image/imageVariations/original' },
1348
+ message: 'The required property `height` is missing at `#/image/imageVariations/original`',
1349
+ name: 'RequiredPropertyError',
1350
+ type: 'error',
1351
+ },
1352
+ {
1353
+ code: 'required-property-error',
1354
+ data: { key: 'aspectRatio', pointer: '#/image/imageVariations/original' },
1355
+ message: 'The required property `aspectRatio` is missing at `#/image/imageVariations/original`',
1356
+ name: 'RequiredPropertyError',
1357
+ type: 'error',
1358
+ },
1359
+ ],
1360
+ oneOf: [{ $ref: 'SquizImage.json' }],
1361
+ pointer: '#/image',
1362
+ value: '{"name":"test-image.jpeg","imageVariations":{"original":{"width":100,"url":"https://www.squiz.net","byteSize":100,"mimeType":"image/jpeg","sha1Hash":"123"}}}',
1363
+ },
1364
+ message: 'Value `{"name":"test-image.jpeg","imageVariations":{"original":{"width":100,"url":"https://www.squiz.net","byteSize":100,"mimeType":"image/jpeg","sha1Hash":"123"}}}` in `#/image` does not match any given oneof schema',
1365
+ },
1366
+ ],
1367
+ '#/link': [
1368
+ {
1369
+ data: {
1370
+ errors: [
1371
+ {
1372
+ code: 'required-property-error',
1373
+ data: { key: 'url', pointer: '#/link' },
1374
+ message: 'The required property `url` is missing at `#/link`',
1375
+ name: 'RequiredPropertyError',
1376
+ type: 'error',
1377
+ },
1378
+ ],
1379
+ oneOf: [{ $ref: 'SquizLink.json' }],
1380
+ pointer: '#/link',
1381
+ value: '{"name":"test-link","target":"_blank"}',
1382
+ },
1383
+ message: 'Value `{"name":"test-link","target":"_blank"}` in `#/link` does not match any given oneof schema',
1384
+ },
1385
+ ],
1386
+ '#/text': [
1387
+ {
1388
+ data: {
1389
+ errors: [
1390
+ {
1391
+ code: 'any-of-error',
1392
+ data: {
1393
+ anyOf: [
1394
+ { $ref: '#/definitions/HigherOrderFormattedNodes' },
1395
+ { $ref: '#/definitions/BaseFormattedNodes' },
1396
+ ],
1397
+ pointer: '#/text/0',
1398
+ value: { children: [{ type: 'text', value: 'hello' }] },
1399
+ },
1400
+ message: 'Object at `#/text/0` does not match any schema',
1401
+ name: 'AnyOfError',
1402
+ type: 'error',
1403
+ },
1404
+ ],
1405
+ oneOf: [{ $ref: 'FormattedText.json' }],
1406
+ pointer: '#/text',
1407
+ value: '[{"children":[{"type":"text","value":"hello"}]}]',
1408
+ },
1409
+ message: 'Value `[{"children":[{"type":"text","value":"hello"}]}]` in `#/text` does not match any given oneof schema',
1410
+ },
1411
+ ],
1412
+ });
1413
+ });
1414
+ it('should validate when MatrixAssetType is being used for a squiz primitive type with resolver', () => {
1415
+ const typeResolver = TypeResolverBuilder_1.TypeResolverBuilder.new()
1416
+ .addPrimitive(primitiveTypes_1.SquizImageType)
1417
+ .addPrimitive(primitiveTypes_1.SquizLinkType)
1418
+ .addPrimitive(primitiveTypes_1.FormattedTextType)
1419
+ .addResolver(primitiveTypes_1.SquizImageType, resolvableTypes_1.MatrixAssetType, () => {
1420
+ return {
1421
+ name: '',
1422
+ imageVariations: {
1423
+ original: {
1424
+ width: 0,
1425
+ height: 0,
1426
+ url: '',
1427
+ mimeType: '',
1428
+ byteSize: 0,
1429
+ sha1Hash: '',
1430
+ aspectRatio: '',
1431
+ },
1432
+ },
1433
+ };
1434
+ })
1435
+ .build();
1436
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(typeResolver, JsonValidationService_1.ComponentInputMetaSchema);
1437
+ const schema = {
1438
+ type: 'object',
1439
+ properties: {
1440
+ image: { type: 'SquizImage' },
1441
+ link: { type: 'SquizLink' },
1442
+ text: { type: 'FormattedText' },
1443
+ asset: {
1444
+ type: 'string',
1445
+ format: 'matrix-asset-uri',
1446
+ },
1447
+ },
1448
+ required: ['image', 'link', 'text', 'asset'],
1449
+ };
1450
+ const formattedText = [
1451
+ {
1452
+ tag: 'p',
1453
+ type: 'tag',
1454
+ children: [{ type: 'text', value: 'hello' }],
1455
+ },
1456
+ ];
1457
+ const input = {
1458
+ image: {
1459
+ matrixAssetId: '123',
1460
+ matrixIdentifier: 'identifier',
1461
+ matrixDomain: 'domain',
1462
+ },
1463
+ link: {
1464
+ name: 'test-link',
1465
+ url: 'https://www.squiz.net',
1466
+ target: '_blank',
1467
+ },
1468
+ text: formattedText,
1469
+ asset: 'matrix-asset://identifier/123',
1470
+ };
1471
+ expect(jsonSchemaService.validateInput(input, schema)).toEqual(true);
1472
+ });
1473
+ it('it should catch MatrixAssetType validation errors when being use for squiz primitive type with resolver', () => {
1474
+ const typeResolver = TypeResolverBuilder_1.TypeResolverBuilder.new()
1475
+ .addPrimitive(primitiveTypes_1.SquizImageType)
1476
+ .addPrimitive(primitiveTypes_1.SquizLinkType)
1477
+ .addPrimitive(primitiveTypes_1.FormattedTextType)
1478
+ .addResolver(primitiveTypes_1.SquizImageType, resolvableTypes_1.MatrixAssetType, () => {
1479
+ return {
1480
+ name: '',
1481
+ imageVariations: {
1482
+ original: {
1483
+ width: 0,
1484
+ height: 0,
1485
+ url: '',
1486
+ mimeType: '',
1487
+ byteSize: 0,
1488
+ sha1Hash: '',
1489
+ aspectRatio: '',
1490
+ },
1491
+ },
1492
+ };
1493
+ })
1494
+ .build();
1495
+ const jsonSchemaService = new JsonValidationService_1.JSONSchemaService(typeResolver, JsonValidationService_1.ComponentInputMetaSchema);
1496
+ const schema = {
1497
+ type: 'object',
1498
+ properties: {
1499
+ image: { type: 'SquizImage' },
1500
+ },
1501
+ required: ['image'],
1502
+ };
1503
+ const input = {
1504
+ //@ts-expect-error - intentionally invalid input
1505
+ image: {
1506
+ matrixIdentifier: 'identifier',
1507
+ },
1508
+ };
1509
+ expectToThrowErrorMatchingTypeAndMessage(() => jsonSchemaService.validateInput(input, schema), SchemaValidationError_1.SchemaValidationError, 'failed validation: Value `{"matrixIdentifier":"identifier"}` in `#/image` does not match any given oneof schema', {
1510
+ '#/image': [
1511
+ {
1512
+ data: {
1513
+ errors: [
1514
+ {
1515
+ code: 'required-property-error',
1516
+ data: { key: 'name', pointer: '#/image' },
1517
+ message: 'The required property `name` is missing at `#/image`',
1518
+ name: 'RequiredPropertyError',
1519
+ type: 'error',
1520
+ },
1521
+ {
1522
+ code: 'required-property-error',
1523
+ data: { key: 'imageVariations', pointer: '#/image' },
1524
+ message: 'The required property `imageVariations` is missing at `#/image`',
1525
+ name: 'RequiredPropertyError',
1526
+ type: 'error',
1527
+ },
1528
+ {
1529
+ code: 'required-property-error',
1530
+ data: { key: 'matrixAssetId', pointer: '#/image' },
1531
+ message: 'The required property `matrixAssetId` is missing at `#/image`',
1532
+ name: 'RequiredPropertyError',
1533
+ type: 'error',
1534
+ },
1535
+ ],
1536
+ oneOf: [{ $ref: 'SquizImage.json' }, { $ref: 'MatrixAsset.json' }],
1537
+ pointer: '#/image',
1538
+ value: '{"matrixIdentifier":"identifier"}',
1539
+ },
1540
+ message: 'Value `{"matrixIdentifier":"identifier"}` in `#/image` does not match any given oneof schema',
1541
+ },
1542
+ ],
1543
+ });
1544
+ });
1545
+ });
1051
1546
  //# sourceMappingURL=JsonValidationService.spec.js.map