@@ -1312,85 +1312,6 @@ subtest dependentRequired => sub {
1312
1312
);
1313
1313
};
1314
1314
1315
- subtest ' evaluate in the middle of a document' => sub {
1316
- $js -> add_schema({
1317
- ' $id' => ' https://myschema' ,
1318
- properties => {
1319
- foo => {
1320
- ' $id' => ' https://my-inner-schema' ,
1321
- allOf => [
1322
- { # <-- evaluation starts here
1323
- type => ' object' ,
1324
- properties => {
1325
- bar => {
1326
- type => ' string' ,
1327
- },
1328
- },
1329
- },
1330
- ],
1331
- },
1332
- },
1333
- });
1334
-
1335
- cmp_result(
1336
- $js -> evaluate(
1337
- {
1338
- bar => [' not a string' ],
1339
- },
1340
- ' https://myschema#/properties/foo/allOf/1' ,
1341
- {
1342
- data_path => ' /request/body' ,
1343
- traversed_schema_path => ' /some/other/thing/$ref/foo/$ref' ,
1344
- initial_schema_uri => ' https://somewhere/else#/foo' ,
1345
- },
1346
- )-> TO_JSON,
1347
- {
1348
- valid => false,
1349
- errors => [
1350
- {
1351
- instanceLocation => ' /request/body' ,
1352
- keywordLocation => ' /some/other/thing/$ref/foo/$ref' ,
1353
- absoluteKeywordLocation => ' https://somewhere/else#/foo' ,
1354
- error => ' EXCEPTION: unable to find resource "https://myschema#/properties/foo/allOf/1"' ,
1355
- },
1356
- ],
1357
- },
1358
- ' provided evaluation uri does not exist' ,
1359
- );
1360
-
1361
- cmp_result(
1362
- $js -> evaluate(
1363
- {
1364
- bar => [' not a string' ],
1365
- },
1366
- ' https://myschema#/properties/foo/allOf/0' , # <-- not the canonical URI!
1367
- {
1368
- data_path => ' /request/body' ,
1369
- traversed_schema_path => ' /some/other/thing/$ref/foo/$ref' ,
1370
- initial_schema_uri => ' https://somewhere/else#/foo' ,
1371
- },
1372
- )-> TO_JSON,
1373
- {
1374
- valid => false,
1375
- errors => [
1376
- {
1377
- instanceLocation => ' /request/body/bar' ,
1378
- keywordLocation => ' /some/other/thing/$ref/foo/$ref/properties/bar/type' ,
1379
- absoluteKeywordLocation => ' https://my-inner-schema#/allOf/0/properties/bar/type' ,
1380
- error => ' got array, not string' ,
1381
- },
1382
- {
1383
- instanceLocation => ' /request/body' ,
1384
- keywordLocation => ' /some/other/thing/$ref/foo/$ref/properties' ,
1385
- absoluteKeywordLocation => ' https://my-inner-schema#/allOf/0/properties' ,
1386
- error => ' not all properties are valid' ,
1387
- },
1388
- ],
1389
- },
1390
- ' error has correct locations from override hash' ,
1391
- );
1392
- };
1393
-
1394
1315
subtest ' numbers in output' => sub {
1395
1316
cmp_result(
1396
1317
$js -> evaluate(
@@ -1437,7 +1358,7 @@ subtest 'numbers in output' => sub {
1437
1358
);
1438
1359
};
1439
1360
1440
- subtest ' effective_base_uri' => sub {
1361
+ subtest ' effective_base_uri and overriding starting locations ' => sub {
1441
1362
cmp_result(
1442
1363
$js -> evaluate(
1443
1364
5,
@@ -1470,6 +1391,50 @@ subtest 'effective_base_uri' => sub {
1470
1391
},
1471
1392
' error locations are relative to the effective_base_uri, but $ref usage is not restricted' ,
1472
1393
);
1394
+
1395
+ # evaluating this document from its root would do nothing, as it is only definitions
1396
+ $js -> add_schema(' /api' , {
1397
+ ' $defs' => {
1398
+ alpha => {
1399
+ items => {
1400
+ ' $ref' => ' #/$defs/beta' ,
1401
+ },
1402
+ },
1403
+ beta => {
1404
+ not => true,
1405
+ },
1406
+ },
1407
+ });
1408
+
1409
+ cmp_result(
1410
+ $js -> evaluate(
1411
+ [ 5 ],
1412
+ ' /api#/$defs/alpha' ,
1413
+ {
1414
+ data_path => ' /html/body/div/div/h1/div/p' , # reported data location
1415
+ traversed_schema_path => ' /some/other/document/$ref' , # reported keywords passed through before we start
1416
+ effective_base_uri => ' https://example.com' , # base uri to use for document locations
1417
+ },
1418
+ )-> TO_JSON,
1419
+ {
1420
+ valid => false,
1421
+ errors => [
1422
+ {
1423
+ instanceLocation => ' /html/body/div/div/h1/div/p/0' ,
1424
+ keywordLocation => ' /some/other/document/$ref/items/$ref/not' ,
1425
+ absoluteKeywordLocation => ' https://example.com/api#/$defs/beta/not' ,
1426
+ error => ' subschema is valid' ,
1427
+ },
1428
+ {
1429
+ instanceLocation => ' /html/body/div/div/h1/div/p' ,
1430
+ keywordLocation => ' /some/other/document/$ref/items' ,
1431
+ absoluteKeywordLocation => ' https://example.com/api#/$defs/alpha/items' ,
1432
+ error => ' subschema is not valid against all items' ,
1433
+ },
1434
+ ],
1435
+ },
1436
+ ' can alter locations with data_path, traversed_schema_path, effective_base_uri' ,
1437
+ );
1473
1438
};
1474
1439
1475
1440
subtest ' recommended_response' => sub {
0 commit comments