Source file jsonschema_validation.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
(** JSON Schema validation. *)
open Jsonschema_core
module Draft07_keywords = Draft07
module Draft06_keywords = Draft06
module Draft04_keywords = Draft04
module Draft03_keywords = Draft03
module Draft2019_09_keywords = Draft2019_09
module Draft2020_12_keywords = Draft2020_12
type validator = Registry.validator
type error = Error.t
type output_format = Flag | Basic | Detailed | Verbose
type annotation = {
keyword : string;
value : Yojson.Safe.t;
instance_location : Json_pointer.t;
schema_location : Json_pointer.t;
keyword_location : Json_pointer.t;
absolute_keyword_location : Uri.t option;
}
type output_unit = {
valid : bool;
keyword_location : Json_pointer.t;
absolute_keyword_location : Uri.t option;
instance_location : Json_pointer.t;
error : string option;
annotation : Yojson.Safe.t option;
errors : output_unit list;
annotations : output_unit list;
}
type result = {
valid : bool;
errors : error list;
annotations : annotation list;
output : output_format -> Yojson.Safe.t;
}
type evaluator = {
validator : validator;
schema : Yojson.Safe.t;
base_uri : Uri.t;
registry : Registry.t;
config : Compiler.config;
id_keyword : string;
draft_rank : int;
compile_schema : ?base_uri:Uri.t -> Yojson.Safe.t -> validator;
}
module type LAYER = sig
val compile :
?format_assertion:bool ->
?base_uri:Uri.t ->
?retriever:(Uri.t -> Yojson.Safe.t option) ->
Yojson.Safe.t ->
validator
val validate : validator -> Yojson.Safe.t -> error list
val is_valid : validator -> Yojson.Safe.t -> bool
val compile_result :
?format_assertion:bool ->
?base_uri:Uri.t ->
?retriever:(Uri.t -> Yojson.Safe.t option) ->
Yojson.Safe.t ->
evaluator
val evaluate : evaluator -> Yojson.Safe.t -> result
val validate_schema :
?base_uri:Uri.t ->
?retriever:(Uri.t -> Yojson.Safe.t option) ->
Yojson.Safe.t ->
error list
val is_valid_schema :
?base_uri:Uri.t ->
?retriever:(Uri.t -> Yojson.Safe.t option) ->
Yojson.Safe.t ->
bool
end
let registry_and_config_with_profile ~schema_dialect ~id_keyword
~allow_boolean_schemas ~ref_siblings_apply ~recursive_ref_enabled
~recursive_ref_target ~dynamic_ref_enabled ~dynamic_ref_targets
~select_config keywords ?(format_assertion = false) ?base_uri ?retriever
schema_json =
let reg =
Registry.create ~schema_dialect
~schema_dialect_selector:Registry.standard_schema_dialect_selector
?retriever ()
in
let base_uri = match base_uri with Some u -> u | None -> Uri.empty in
Registry.add reg base_uri schema_json;
let config : Compiler.config =
{
keywords;
format_assertion;
id_keyword;
allow_boolean_schemas;
ref_siblings_apply;
recursive_ref_enabled;
recursive_ref_target;
dynamic_ref_enabled;
dynamic_ref_targets;
select_config;
}
in
(reg, config, base_uri)
let compile_with_profile ~schema_dialect ~id_keyword ~allow_boolean_schemas
~ref_siblings_apply ~recursive_ref_enabled ~recursive_ref_target
~dynamic_ref_enabled ~dynamic_ref_targets ~select_config keywords
?format_assertion ?base_uri ?retriever schema_json =
let reg, config, base_uri =
registry_and_config_with_profile ~schema_dialect ~id_keyword
~allow_boolean_schemas ~ref_siblings_apply ~recursive_ref_enabled
~recursive_ref_target ~dynamic_ref_enabled ~dynamic_ref_targets
~select_config keywords ?format_assertion ?base_uri ?retriever schema_json
in
Compiler.compile config reg ~base_uri schema_json
let compile_draft06 keywords =
compile_with_profile ~schema_dialect:Registry.draft06_schema_dialect
~id_keyword:"$id" ~allow_boolean_schemas:true ~ref_siblings_apply:false
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(fun config _ -> config)
keywords
let compile_draft04 keywords =
compile_with_profile ~schema_dialect:Registry.draft04_schema_dialect
~id_keyword:"id" ~allow_boolean_schemas:false ~ref_siblings_apply:false
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(fun config _ -> config)
keywords
let compile_draft03 keywords =
compile_with_profile ~schema_dialect:Registry.draft03_schema_dialect
~id_keyword:"id" ~allow_boolean_schemas:false ~ref_siblings_apply:false
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(fun config _ -> config)
keywords
let strip_trailing_hash s =
let len = String.length s in
if len > 0 && s.[len - 1] = '#' then String.sub s 0 (len - 1) else s
let schema_uri = function
| `Assoc pairs -> (
match List.assoc_opt "$schema" pairs with
| Some (`String uri) -> Some (strip_trailing_hash uri)
| _ -> None)
| _ -> None
let draft2019_09_select_config ?retriever (config : Compiler.config) schema_json
=
match schema_uri schema_json with
| Some
( "http://json-schema.org/draft-07/schema"
| "https://json-schema.org/draft-07/schema" ) ->
{
config with
keywords = Draft07_keywords.all_keywords;
ref_siblings_apply = false;
recursive_ref_enabled = false;
recursive_ref_target = None;
}
| Some "https://json-schema.org/draft/2020-12/schema"
| Some "http://json-schema.org/draft/2020-12/schema" ->
{
config with
keywords =
Draft2020_12_keywords.keywords_for_schema
~format_assertion:config.format_assertion ?retriever schema_json;
ref_siblings_apply = true;
dynamic_ref_enabled = true;
recursive_ref_enabled = false;
recursive_ref_target = None;
}
| Some "https://json-schema.org/draft/2019-09/schema"
| Some "http://json-schema.org/draft/2019-09/schema"
| Some _ ->
{
config with
keywords =
Draft2019_09_keywords.keywords_for_schema ?retriever schema_json;
}
| None -> config
let draft07_select_config ?retriever (config : Compiler.config) schema_json =
match schema_uri schema_json with
| Some "https://json-schema.org/draft/2019-09/schema"
| Some "http://json-schema.org/draft/2019-09/schema" ->
{
config with
keywords =
Draft2019_09_keywords.keywords_for_schema ?retriever schema_json;
ref_siblings_apply = true;
recursive_ref_enabled = true;
recursive_ref_target = None;
}
| Some "https://json-schema.org/draft/2020-12/schema"
| Some "http://json-schema.org/draft/2020-12/schema" ->
{
config with
keywords =
Draft2020_12_keywords.keywords_for_schema
~format_assertion:config.format_assertion ?retriever schema_json;
ref_siblings_apply = true;
dynamic_ref_enabled = true;
recursive_ref_enabled = false;
recursive_ref_target = None;
}
| _ -> config
let draft2020_12_select_config ?retriever (config : Compiler.config) schema_json
=
match schema_uri schema_json with
| Some
( "http://json-schema.org/draft-07/schema"
| "https://json-schema.org/draft-07/schema" ) ->
{
config with
keywords = Draft07_keywords.all_keywords;
ref_siblings_apply = false;
recursive_ref_enabled = false;
recursive_ref_target = None;
dynamic_ref_enabled = false;
dynamic_ref_targets = [];
}
| Some "https://json-schema.org/draft/2019-09/schema"
| Some "http://json-schema.org/draft/2019-09/schema" ->
{
config with
keywords =
Draft2019_09_keywords.keywords_for_schema ?retriever schema_json;
ref_siblings_apply = true;
recursive_ref_enabled = true;
recursive_ref_target = None;
dynamic_ref_enabled = false;
dynamic_ref_targets = [];
}
| Some "https://json-schema.org/draft/2020-12/schema"
| Some "http://json-schema.org/draft/2020-12/schema"
| Some _ ->
{
config with
keywords =
Draft2020_12_keywords.keywords_for_schema
~format_assertion:config.format_assertion ?retriever schema_json;
ref_siblings_apply = true;
recursive_ref_enabled = false;
recursive_ref_target = None;
dynamic_ref_enabled = true;
}
| None -> config
let compile_draft07 ?(format_assertion = false) ?base_uri ?retriever schema_json
=
compile_with_profile ~schema_dialect:Registry.draft07_schema_dialect
~id_keyword:"$id" ~allow_boolean_schemas:true ~ref_siblings_apply:false
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(draft07_select_config ?retriever)
Draft07_keywords.all_keywords ~format_assertion ?base_uri ?retriever
schema_json
let compile_draft2019_09 ?(format_assertion = false) ?base_uri ?retriever
schema_json =
let keywords =
Draft2019_09_keywords.keywords_for_schema ?retriever schema_json
in
compile_with_profile ~schema_dialect:Registry.draft2019_09_schema_dialect
~id_keyword:"$id" ~allow_boolean_schemas:true ~ref_siblings_apply:true
~recursive_ref_enabled:true ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(draft2019_09_select_config ?retriever)
keywords ~format_assertion ?base_uri ?retriever schema_json
let compile_draft2020_12 ?(format_assertion = false) ?base_uri ?retriever
schema_json =
let keywords =
Draft2020_12_keywords.keywords_for_schema ~format_assertion ?retriever
schema_json
in
compile_with_profile ~schema_dialect:Registry.draft2020_12_schema_dialect
~id_keyword:"$id" ~allow_boolean_schemas:true ~ref_siblings_apply:true
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:true ~dynamic_ref_targets:[]
~select_config:(draft2020_12_select_config ?retriever)
keywords ~format_assertion ?base_uri ?retriever schema_json
let metaschema_retriever ?retriever uri =
match Metaschema_bundle.find uri with
| Some metaschema -> Some metaschema
| None -> ( match retriever with Some f -> f uri | None -> None)
let compile_metaschema ?retriever meta_uri meta_json =
let retriever = metaschema_retriever ?retriever in
let compile_by_uri uri =
match strip_trailing_hash uri with
| "http://json-schema.org/draft-03/schema"
| "https://json-schema.org/draft-03/schema" ->
compile_draft03 Draft03_keywords.all_keywords ~retriever meta_json
| "http://json-schema.org/draft-04/schema"
| "https://json-schema.org/draft-04/schema" ->
compile_draft04 Draft04_keywords.all_keywords ~retriever meta_json
| "http://json-schema.org/draft-06/schema"
| "https://json-schema.org/draft-06/schema" ->
compile_draft06 Draft06_keywords.all_keywords ~retriever meta_json
| "http://json-schema.org/draft-07/schema"
| "https://json-schema.org/draft-07/schema" ->
compile_draft07 ~retriever meta_json
| "http://json-schema.org/draft/2019-09/schema"
| "https://json-schema.org/draft/2019-09/schema" ->
compile_draft2019_09 ~retriever meta_json
| "http://json-schema.org/draft/2020-12/schema"
| "https://json-schema.org/draft/2020-12/schema" ->
compile_draft2020_12 ~retriever meta_json
| _ -> compile_draft2020_12 ~retriever meta_json
in
match schema_uri meta_json with
| Some uri -> compile_by_uri uri
| None -> compile_by_uri (Uri.to_string meta_uri)
let metaschema_uri_of_string s =
try Ok (Uri.of_string s) with _ -> Error "metaschema URI cannot be parsed"
let resolve_metaschema ?retriever schema_uri =
match metaschema_uri_of_string schema_uri with
| Error _ as error -> error
| Ok uri -> (
let retriever = metaschema_retriever ?retriever in
let fetch_uri = Uri_util.without_fragment uri in
match retriever fetch_uri with
| Some metaschema -> Ok (fetch_uri, metaschema)
| None -> Error "metaschema URI could not be resolved")
let run_validate v instance = v instance Json_pointer.empty
let run_is_valid v instance = run_validate v instance = []
let schema_document_error path keyword message =
Error.make ~instance_path:path ~schema_path:path ~keyword message
let supported_vocabulary_uris =
[
"https://json-schema.org/draft/2019-09/vocab/core";
"https://json-schema.org/draft/2019-09/vocab/applicator";
"https://json-schema.org/draft/2019-09/vocab/validation";
"https://json-schema.org/draft/2019-09/vocab/meta-data";
"https://json-schema.org/draft/2019-09/vocab/format";
"https://json-schema.org/draft/2019-09/vocab/content";
"https://json-schema.org/draft/2020-12/vocab/core";
"https://json-schema.org/draft/2020-12/vocab/applicator";
"https://json-schema.org/draft/2020-12/vocab/unevaluated";
"https://json-schema.org/draft/2020-12/vocab/validation";
"https://json-schema.org/draft/2020-12/vocab/meta-data";
"https://json-schema.org/draft/2020-12/vocab/format-annotation";
"https://json-schema.org/draft/2020-12/vocab/format-assertion";
"https://json-schema.org/draft/2020-12/vocab/content";
]
let supported_vocabulary_uri uri =
List.mem (strip_trailing_hash uri) supported_vocabulary_uris
let required_unsupported_vocabulary_uris = function
| `Assoc pairs -> (
match List.assoc_opt "$vocabulary" pairs with
| Some (`Assoc vocabularies) ->
vocabularies
|> List.filter_map (fun (uri, required) ->
match required with
| `Bool true when not (supported_vocabulary_uri uri) -> Some uri
| _ -> None)
| _ -> [])
| _ -> []
let rec rebase_schema_error base_path (error : Error.t) =
{
error with
instance_path = base_path @ error.instance_path;
context = List.map (rebase_schema_error base_path) error.context;
}
let rec path_has_prefix prefix path =
match (prefix, path) with
| [], _ -> true
| p :: ps, x :: xs when p = x -> path_has_prefix ps xs
| _ -> false
let rec drop_path_prefix prefix path =
match (prefix, path) with
| [], rest -> Some rest
| p :: ps, x :: xs when p = x -> drop_path_prefix ps xs
| _ -> None
let replace_list_at index f values =
List.mapi (fun i value -> if i = index then f value else value) values
let rec replace_json_at path replacement json =
match (path, json) with
| [], _ -> replacement
| token :: rest, `Assoc pairs ->
`Assoc
(List.map
(fun (key, value) ->
if key = token then (key, replace_json_at rest replacement value)
else (key, value))
pairs)
| token :: rest, `List values -> (
match int_of_string_opt token with
| Some index when index >= 0 && index < List.length values ->
`List
(replace_list_at index (replace_json_at rest replacement) values)
| _ -> json)
| _ -> json
let schema_with_masked_embedded_resources
(all_resources : Registry.schema_resource list)
(resource : Registry.schema_resource) =
all_resources
|> List.filter_map (fun (candidate : Registry.schema_resource) ->
if
candidate.path <> resource.path
&& path_has_prefix resource.path candidate.path
then drop_path_prefix resource.path candidate.path
else None)
|> List.fold_left
(fun schema path -> replace_json_at path (`Bool true) schema)
resource.schema
let validate_resource_against_metaschema ?retriever all_resources
(resource : Registry.schema_resource) =
match resolve_metaschema ?retriever resource.schema_uri with
| Error message ->
[
schema_document_error
(Json_pointer.append resource.path "$schema")
"$schema" message;
]
| Ok (meta_uri, metaschema) -> (
match required_unsupported_vocabulary_uris metaschema with
| unsupported_uri :: _ ->
[
schema_document_error
(Json_pointer.append resource.path "$schema")
"$vocabulary"
(Printf.sprintf "required vocabulary is not supported: %s"
unsupported_uri);
]
| [] ->
let schema =
schema_with_masked_embedded_resources all_resources resource
in
let validator = compile_metaschema ?retriever meta_uri metaschema in
validator schema Json_pointer.empty
|> List.map (rebase_schema_error resource.path))
let root_declares_schema_uri = function
| `Assoc pairs -> (
match List.assoc_opt "$schema" pairs with
| Some (`String _) -> true
| _ -> false)
| _ -> false
let validate_schema_with_profile ~schema_dialect ~default_schema_uri ?base_uri:_
?retriever schema_json =
let local_errors =
Registry.validate_schema_keywords ~schema_dialect
~schema_dialect_selector:Registry.standard_schema_dialect_selector
schema_json
in
if local_errors <> [] then local_errors
else
let declared_resources =
Registry.schema_resources_with_schema_uri ~schema_dialect
~schema_dialect_selector:Registry.standard_schema_dialect_selector
schema_json
in
let resources =
if root_declares_schema_uri schema_json then declared_resources
else
{
Registry.path = Json_pointer.empty;
schema_uri = default_schema_uri;
schema = schema_json;
}
:: declared_resources
in
resources
|> List.concat_map
(validate_resource_against_metaschema ?retriever resources)
let is_valid_schema_with_profile ~schema_dialect ~default_schema_uri ?base_uri
?retriever schema_json =
validate_schema_with_profile ~schema_dialect ~default_schema_uri ?base_uri
?retriever schema_json
= []
let effective_root_base ~id_keyword base_uri schema_json =
match schema_json with
| `Assoc pairs -> (
match List.assoc_opt id_keyword pairs with
| Some (`String id_str) ->
let id_uri = Uri.of_string id_str in
let resolved = Uri_util.resolve ~base:base_uri id_uri in
if Uri_util.fragment id_uri <> None && Uri.path id_uri = "" then
base_uri
else Uri_util.without_fragment resolved
| _ -> base_uri)
| _ -> base_uri
let absolute_keyword_location base_uri keyword_location =
if Uri.to_string base_uri = "" then None
else
Some
(Uri.with_fragment base_uri
(Some (Json_pointer.to_string keyword_location)))
let metadata_keywords =
[
"title";
"description";
"default";
"deprecated";
"readOnly";
"writeOnly";
"examples";
]
let content_annotation_keywords =
[ "contentEncoding"; "contentMediaType"; "contentSchema" ]
let keyword_names (keywords : Compiler.keyword_compiler list) =
List.map
(fun (keyword : Compiler.keyword_compiler) -> keyword.keyword)
keywords
let standard_keyword_names =
List.sort_uniq String.compare
([
"$anchor";
"$comment";
"$defs";
"$dynamicAnchor";
"$dynamicRef";
"$id";
"$recursiveAnchor";
"$recursiveRef";
"$ref";
"$schema";
"$vocabulary";
"definitions";
"id";
"format";
]
@ metadata_keywords @ content_annotation_keywords
@ keyword_names Draft03_keywords.all_keywords
@ keyword_names Draft04_keywords.all_keywords
@ keyword_names Draft06_keywords.all_keywords
@ keyword_names Draft07_keywords.all_keywords
@ keyword_names Draft2019_09_keywords.all_keywords
@ keyword_names Draft2020_12_keywords.all_keywords)
let annotation_at base_uri schema_path instance_path keyword value =
let keyword_location = Json_pointer.append schema_path keyword in
{
keyword;
value;
instance_location = instance_path;
schema_location = schema_path;
keyword_location;
absolute_keyword_location =
absolute_keyword_location base_uri keyword_location;
}
let metadata_annotations_at base_uri schema_path instance_path pairs =
List.filter_map
(fun keyword ->
match List.assoc_opt keyword pairs with
| Some value ->
Some (annotation_at base_uri schema_path instance_path keyword value)
| None -> None)
metadata_keywords
let unknown_annotations_at base_uri schema_path instance_path pairs =
List.filter_map
(fun (keyword, value) ->
if List.mem keyword standard_keyword_names then None
else Some (annotation_at base_uri schema_path instance_path keyword value))
pairs
let format_annotations_at base_uri schema_path instance_path pairs instance =
match (instance, List.assoc_opt "format" pairs) with
| `String _, Some (`String _ as value) ->
[ annotation_at base_uri schema_path instance_path "format" value ]
| _ -> []
let content_annotations_at evaluator base_uri schema_path instance_path pairs
instance =
if evaluator.draft_rank < 7 then []
else
match instance with
| `String _ ->
let string_keyword keyword =
match List.assoc_opt keyword pairs with
| Some (`String _ as value) ->
[ annotation_at base_uri schema_path instance_path keyword value ]
| _ -> []
in
let content_schema =
if evaluator.draft_rank >= 2019 then
match
( List.assoc_opt "contentMediaType" pairs,
List.assoc_opt "contentSchema" pairs )
with
| Some (`String _), Some value ->
[
annotation_at base_uri schema_path instance_path
"contentSchema" value;
]
| _ -> []
else []
in
string_keyword "contentMediaType"
@ string_keyword "contentEncoding"
@ content_schema
| _ -> []
let schema_valid_at evaluator base_uri schema instance path =
let v = evaluator.compile_schema ~base_uri schema in
v instance path = []
let list_indexed values = List.mapi (fun index value -> (index, value)) values
let add_path path token = Json_pointer.append path token
let schema_local_base evaluator base_uri pairs =
match List.assoc_opt evaluator.id_keyword pairs with
| Some (`String id_str) ->
let id_uri = Uri.of_string id_str in
let resolved = Uri_util.resolve ~base:base_uri id_uri in
if Uri_util.fragment id_uri <> None && Uri.path id_uri = "" then base_uri
else Uri_util.without_fragment resolved
| _ -> base_uri
let add_dynamic_resource_targets registry resource_uri targets =
Registry.dynamic_anchors_for_resource registry resource_uri
|> List.fold_left
(fun acc (name, uri) ->
if List.mem_assoc name acc then acc else acc @ [ (name, uri) ])
targets
let recursive_ref_target_at evaluator local_base_uri pairs recursive_ref_target
=
match List.assoc_opt "$recursiveAnchor" pairs with
| Some (`Bool true) -> (
match recursive_ref_target with
| Some _ as target -> target
| None -> Some local_base_uri)
| _ when List.mem_assoc evaluator.id_keyword pairs -> None
| _ -> recursive_ref_target
let dynamic_ref_plain_name ref_str =
let uri = Uri.of_string ref_str in
match Uri_util.fragment uri with
| Some name when name <> "" && name.[0] <> '/' -> Some name
| _ -> None
let resolve_ref_uri evaluator base_uri local_base_uri dynamic_ref_targets
recursive_ref_target keyword ref_str =
match (keyword, ref_str, recursive_ref_target) with
| "$recursiveRef", "#", Some target -> Uri.with_fragment target (Some "")
| "$dynamicRef", _, _ when evaluator.config.dynamic_ref_enabled -> (
let ref_uri = Uri.of_string ref_str in
let resolved = Uri_util.resolve ~base:local_base_uri ref_uri in
match dynamic_ref_plain_name ref_str with
| Some name
when Registry.is_dynamic_anchor_uri evaluator.registry resolved -> (
match List.assoc_opt name dynamic_ref_targets with
| Some target -> target
| None -> resolved)
| _ -> resolved)
| "$ref", _, _ when not evaluator.config.ref_siblings_apply ->
Uri_util.resolve ~base:base_uri (Uri.of_string ref_str)
| _ -> Uri_util.resolve ~base:local_base_uri (Uri.of_string ref_str)
type evaluation_facts = {
annotations : annotation list;
evaluated_properties : string list;
evaluated_items : int list;
}
let empty_facts =
{ annotations = []; evaluated_properties = []; evaluated_items = [] }
let add_unique value values =
if List.mem value values then values else value :: values
let merge_facts left right =
{
annotations = left.annotations @ right.annotations;
evaluated_properties =
List.fold_left
(fun acc value -> add_unique value acc)
left.evaluated_properties right.evaluated_properties;
evaluated_items =
List.fold_left
(fun acc value -> add_unique value acc)
left.evaluated_items right.evaluated_items;
}
let merge_many facts = List.fold_left merge_facts empty_facts facts
let merge_annotations left right =
{ left with annotations = left.annotations @ right.annotations }
let add_evaluated_property name facts =
{
facts with
evaluated_properties = add_unique name facts.evaluated_properties;
}
let add_evaluated_item index facts =
{ facts with evaluated_items = add_unique index facts.evaluated_items }
let facts_of_annotations annotations = { empty_facts with annotations }
let rec collect_facts ?(depth = 32) ?(dynamic_ref_targets = [])
?recursive_ref_target evaluator base_uri schema_path instance_path schema
instance =
if depth <= 0 then empty_facts
else if not (schema_valid_at evaluator base_uri schema instance instance_path)
then empty_facts
else
match schema with
| `Assoc pairs ->
let local_base_uri = schema_local_base evaluator base_uri pairs in
let recursive_ref_target =
recursive_ref_target_at evaluator local_base_uri pairs
recursive_ref_target
in
let dynamic_ref_targets =
if evaluator.config.dynamic_ref_enabled then
add_dynamic_resource_targets evaluator.registry local_base_uri
dynamic_ref_targets
else dynamic_ref_targets
in
let ref_facts =
collect_reference_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri local_base_uri schema_path
instance_path pairs instance
in
if
List.mem_assoc "$ref" pairs && not evaluator.config.ref_siblings_apply
then ref_facts
else
merge_facts
(merge_facts
(facts_of_annotations
(metadata_annotations_at local_base_uri schema_path
instance_path pairs
@ format_annotations_at local_base_uri schema_path
instance_path pairs instance
@ content_annotations_at evaluator local_base_uri schema_path
instance_path pairs instance
@ unknown_annotations_at local_base_uri schema_path
instance_path pairs))
ref_facts)
(collect_applicator_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator local_base_uri schema_path
instance_path pairs instance)
| _ -> empty_facts
and collect_child_facts ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path schema instance =
collect_facts ~depth:(depth - 1) ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path schema instance
and collect_reference_facts ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri local_base_uri _schema_path instance_path pairs instance
=
let collect keyword enabled acc =
if not enabled then acc
else
match List.assoc_opt keyword pairs with
| Some (`String ref_str) -> (
let resolved =
resolve_ref_uri evaluator base_uri local_base_uri
dynamic_ref_targets recursive_ref_target keyword ref_str
in
match
Registry.resolve_with_base_and_path evaluator.registry resolved
with
| Some (target_schema, target_base, target_path)
when schema_valid_at evaluator target_base target_schema instance
instance_path ->
merge_facts acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator target_base target_path
instance_path target_schema instance)
| _ -> acc)
| _ -> acc
in
empty_facts |> collect "$ref" true
|> collect "$recursiveRef" evaluator.config.recursive_ref_enabled
|> collect "$dynamicRef" evaluator.config.dynamic_ref_enabled
and collect_applicator_facts ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path pairs instance =
let collect_schema_array keyword =
match List.assoc_opt keyword pairs with
| Some (`List schemas) ->
schemas |> list_indexed
|> List.fold_left
(fun acc (index, schema) ->
merge_facts acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path
(add_path schema_path keyword)
(string_of_int index))
instance_path schema instance))
empty_facts
| _ -> empty_facts
in
let prior =
merge_many
[
collect_object_applicator_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
pairs instance;
collect_array_applicator_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
pairs instance;
collect_schema_array "allOf";
collect_schema_array "anyOf";
collect_schema_array "oneOf";
collect_dependent_schema_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
pairs instance;
collect_conditional_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
pairs instance;
]
in
merge_facts prior
(collect_unevaluated_facts ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path pairs instance prior)
and collect_object_applicator_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path pairs
instance =
match instance with
| `Assoc instance_pairs ->
let properties =
match List.assoc_opt "properties" pairs with
| Some (`Assoc props) -> props
| _ -> []
in
let property_annotations =
properties
|> List.fold_left
(fun acc (name, schema) ->
match List.assoc_opt name instance_pairs with
| Some value ->
let child_path = add_path instance_path name in
if schema_valid_at evaluator base_uri schema value child_path
then
add_evaluated_property name
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path (add_path schema_path "properties") name)
child_path schema value))
else acc
| None -> acc)
empty_facts
in
let pattern_properties =
match List.assoc_opt "patternProperties" pairs with
| Some (`Assoc patterns) ->
patterns
|> List.filter_map (fun (pattern, schema) ->
match Regex.compile pattern with
| Ok re -> Some (pattern, re, schema)
| Error _ -> None)
| _ -> []
in
let pattern_annotations =
instance_pairs
|> List.fold_left
(fun acc (name, value) ->
pattern_properties
|> List.fold_left
(fun acc (pattern, re, schema) ->
if Regex.matches re name then
let child_path = add_path instance_path name in
if
schema_valid_at evaluator base_uri schema value
child_path
then
add_evaluated_property name
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path
(add_path schema_path "patternProperties")
pattern)
child_path schema value))
else acc
else acc)
acc)
empty_facts
in
let known_property name =
List.mem_assoc name properties
|| List.exists
(fun (_, re, _) -> Regex.matches re name)
pattern_properties
in
let additional_annotations =
match List.assoc_opt "additionalProperties" pairs with
| Some ((`Assoc _ | `Bool _) as schema) ->
instance_pairs
|> List.fold_left
(fun acc (name, value) ->
if known_property name then acc
else
let child_path = add_path instance_path name in
if
schema_valid_at evaluator base_uri schema value
child_path
then
add_evaluated_property name
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path schema_path "additionalProperties")
child_path schema value))
else acc)
empty_facts
| _ -> empty_facts
in
merge_many
[ property_annotations; pattern_annotations; additional_annotations ]
| _ -> empty_facts
and collect_array_applicator_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path pairs
instance =
match instance with
| `List items ->
let prefix_len, prefix_annotations =
match List.assoc_opt "prefixItems" pairs with
| Some (`List schemas) when evaluator.draft_rank >= 2020 ->
let annotations =
items |> list_indexed
|> List.fold_left
(fun acc (index, item) ->
if index < List.length schemas then
let schema = List.nth schemas index in
let item_path =
add_path instance_path (string_of_int index)
in
if
schema_valid_at evaluator base_uri schema item
item_path
then
add_evaluated_item index
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path
(add_path schema_path "prefixItems")
(string_of_int index))
item_path schema item))
else acc
else acc)
empty_facts
in
(List.length schemas, annotations)
| _ -> (0, empty_facts)
in
let item_annotations =
match List.assoc_opt "items" pairs with
| Some (`List schemas) when evaluator.draft_rank < 2020 ->
items |> list_indexed
|> List.fold_left
(fun acc (index, item) ->
if index < List.length schemas then
let schema = List.nth schemas index in
let item_path =
add_path instance_path (string_of_int index)
in
if schema_valid_at evaluator base_uri schema item item_path
then
add_evaluated_item index
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path
(add_path schema_path "items")
(string_of_int index))
item_path schema item))
else acc
else acc)
empty_facts
| Some ((`Assoc _ | `Bool _) as schema) ->
items |> list_indexed
|> List.fold_left
(fun acc (index, item) ->
if evaluator.draft_rank >= 2020 && index < prefix_len then
acc
else
let item_path =
add_path instance_path (string_of_int index)
in
if schema_valid_at evaluator base_uri schema item item_path
then
add_evaluated_item index
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path schema_path "items")
item_path schema item))
else acc)
empty_facts
| _ -> empty_facts
in
let contains_annotations =
match List.assoc_opt "contains" pairs with
| Some schema ->
items |> list_indexed
|> List.fold_left
(fun acc (index, item) ->
let item_path =
add_path instance_path (string_of_int index)
in
if schema_valid_at evaluator base_uri schema item item_path
then
add_evaluated_item index
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path schema_path "contains")
item_path schema item))
else acc)
empty_facts
| None -> empty_facts
in
merge_many [ prefix_annotations; item_annotations; contains_annotations ]
| _ -> empty_facts
and collect_dependent_schema_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path pairs
instance =
match (instance, List.assoc_opt "dependentSchemas" pairs) with
| `Assoc instance_pairs, Some (`Assoc schemas) ->
schemas
|> List.fold_left
(fun acc (name, schema) ->
if List.mem_assoc name instance_pairs then
merge_facts acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path (add_path schema_path "dependentSchemas") name)
instance_path schema instance)
else acc)
empty_facts
| _ -> empty_facts
and collect_conditional_facts ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path pairs instance =
match List.assoc_opt "if" pairs with
| Some if_schema -> (
if schema_valid_at evaluator base_uri if_schema instance instance_path
then
let if_facts =
collect_child_facts ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri
(add_path schema_path "if")
instance_path if_schema instance
in
merge_facts if_facts
(match List.assoc_opt "then" pairs with
| Some then_schema ->
collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path schema_path "then")
instance_path then_schema instance
| None -> empty_facts)
else
match List.assoc_opt "else" pairs with
| Some else_schema ->
collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path schema_path "else")
instance_path else_schema instance
| None -> empty_facts)
| None -> empty_facts
and collect_unevaluated_facts ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path pairs instance prior =
if evaluator.draft_rank < 2019 then empty_facts
else
let property_facts =
match (instance, List.assoc_opt "unevaluatedProperties" pairs) with
| `Assoc instance_pairs, Some (`Bool true) ->
List.fold_left
(fun acc (name, _) ->
if List.mem name prior.evaluated_properties then acc
else add_evaluated_property name acc)
empty_facts instance_pairs
| `Assoc instance_pairs, Some ((`Assoc _ | `Bool _) as schema) ->
instance_pairs
|> List.fold_left
(fun acc (name, value) ->
if List.mem name prior.evaluated_properties then acc
else
let child_path = add_path instance_path name in
if schema_valid_at evaluator base_uri schema value child_path
then
add_evaluated_property name
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path schema_path "unevaluatedProperties")
child_path schema value))
else acc)
empty_facts
| _ -> empty_facts
in
let item_facts =
match (instance, List.assoc_opt "unevaluatedItems" pairs) with
| `List items, Some (`Bool true) ->
items |> list_indexed
|> List.fold_left
(fun acc (index, _) ->
if List.mem index prior.evaluated_items then acc
else add_evaluated_item index acc)
empty_facts
| `List items, Some ((`Assoc _ | `Bool _) as schema) ->
items |> list_indexed
|> List.fold_left
(fun acc (index, item) ->
if List.mem index prior.evaluated_items then acc
else
let item_path =
add_path instance_path (string_of_int index)
in
if schema_valid_at evaluator base_uri schema item item_path
then
add_evaluated_item index
(merge_annotations acc
(collect_child_facts ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path schema_path "unevaluatedItems")
item_path schema item))
else acc)
empty_facts
| _ -> empty_facts
in
merge_facts property_facts item_facts
let collect_annotations evaluator base_uri schema_path instance_path schema
instance =
(collect_facts evaluator base_uri schema_path instance_path schema instance)
.annotations
let output_unit ?error ?annotation ?(errors = []) ?(annotations = []) ~valid
~keyword_location ?absolute_keyword_location ~instance_location () =
{
valid;
keyword_location;
absolute_keyword_location;
instance_location;
error;
annotation;
errors;
annotations;
}
let output_unit_of_annotation (annotation : annotation) =
output_unit ~valid:true ~keyword_location:annotation.keyword_location
?absolute_keyword_location:annotation.absolute_keyword_location
~instance_location:annotation.instance_location ~annotation:annotation.value
()
let error_absolute_keyword_location base_uri (error : error) =
absolute_keyword_location base_uri error.schema_path
let output_unit_of_error_leaf base_uri (error : error) =
output_unit ~valid:false ~keyword_location:error.schema_path
?absolute_keyword_location:(error_absolute_keyword_location base_uri error)
~instance_location:error.instance_path ~error:error.message ()
let rec detailed_output_unit_of_error base_uri (error : error) =
output_unit ~valid:false ~keyword_location:error.schema_path
?absolute_keyword_location:(error_absolute_keyword_location base_uri error)
~instance_location:error.instance_path ~error:error.message
~errors:(List.map (detailed_output_unit_of_error base_uri) error.context)
()
let rec basic_output_units_of_error base_uri error =
output_unit_of_error_leaf base_uri error
:: List.concat_map (basic_output_units_of_error base_uri) error.context
let rec json_of_output_unit (unit : output_unit) =
let required =
[
("valid", `Bool unit.valid);
("keywordLocation", `String (Json_pointer.to_string unit.keyword_location));
( "instanceLocation",
`String (Json_pointer.to_string unit.instance_location) );
]
in
let optional =
(match unit.absolute_keyword_location with
| None -> []
| Some uri -> [ ("absoluteKeywordLocation", `String (Uri.to_string uri)) ])
@ (match unit.error with
| None -> []
| Some message -> [ ("error", `String message) ])
@ (match unit.annotation with
| None -> []
| Some value -> [ ("annotation", value) ])
@ (match unit.errors with
| [] -> []
| errors -> [ ("errors", `List (List.map json_of_output_unit errors)) ])
@
match unit.annotations with
| [] -> []
| annotations ->
[ ("annotations", `List (List.map json_of_output_unit annotations)) ]
in
`Assoc (required @ optional)
let rec path_has_prefix prefix path =
match (prefix, path) with
| [], _ -> true
| _ :: _, [] -> false
| p :: ps, x :: xs -> p = x && path_has_prefix ps xs
let rec flatten_errors (errors : error list) =
errors
@ List.concat_map
(fun (error : Error.t) -> flatten_errors error.context)
errors
let json_of_root_output_unit root_unit = json_of_output_unit root_unit
let errors_under schema_path (all_errors : error list) =
List.filter
(fun (error : Error.t) -> path_has_prefix schema_path error.schema_path)
all_errors
let errors_at schema_path (all_errors : error list) =
List.filter
(fun (error : Error.t) -> error.schema_path = schema_path)
all_errors
let verbose_keyword_unit base_uri schema_path instance_path ?(children = [])
(all_errors : error list) =
let valid =
errors_under schema_path all_errors = []
&& List.for_all (fun (child : output_unit) -> child.valid) children
in
let absolute_keyword_location =
absolute_keyword_location base_uri schema_path
in
if valid then
output_unit ~valid:true ~keyword_location:schema_path
?absolute_keyword_location ~instance_location:instance_path
~errors:children ()
else
match children with
| _ :: _ ->
output_unit ~valid:false ~keyword_location:schema_path
?absolute_keyword_location ~instance_location:instance_path
~errors:children ()
| [] -> (
match errors_at schema_path all_errors with
| error :: _ ->
output_unit ~valid:false ~keyword_location:schema_path
?absolute_keyword_location ~instance_location:error.instance_path
~error:error.message
~errors:
(List.map
(detailed_output_unit_of_error base_uri)
error.context)
()
| [] ->
output_unit ~valid:false ~keyword_location:schema_path
?absolute_keyword_location ~instance_location:instance_path
~error:"validation failed" ())
let verbose_additional_properties_unit base_uri schema_path instance_path pairs
instance (all_errors : error list) =
match instance with
| `Assoc instance_pairs ->
let keyword_path = add_path schema_path "additionalProperties" in
let property_names =
match List.assoc_opt "properties" pairs with
| Some (`Assoc props) -> List.map fst props
| _ -> []
in
let patterns =
match List.assoc_opt "patternProperties" pairs with
| Some (`Assoc pattern_schemas) ->
List.filter_map
(fun (pattern, _) ->
match Regex.compile pattern with
| Ok re -> Some re
| Error _ -> None)
pattern_schemas
| _ -> []
in
let is_additional name =
not
(List.mem name property_names
|| List.exists (fun re -> Regex.matches re name) patterns)
in
let additional_names =
instance_pairs |> List.map fst |> List.filter is_additional
in
let leaf_errors =
all_errors
|> List.filter (fun (error : Error.t) ->
error.schema_path = keyword_path
&& List.exists
(fun name -> error.instance_path = add_path instance_path name)
additional_names)
in
verbose_keyword_unit base_uri keyword_path instance_path
~children:
(List.map (detailed_output_unit_of_error base_uri) leaf_errors)
all_errors
| _ ->
verbose_keyword_unit base_uri
(add_path schema_path "additionalProperties")
instance_path all_errors
let verbose_direct_keyword_names =
[
"type";
"enum";
"const";
"multipleOf";
"maximum";
"exclusiveMaximum";
"minimum";
"exclusiveMinimum";
"maxLength";
"minLength";
"pattern";
"maxItems";
"minItems";
"uniqueItems";
"maxContains";
"minContains";
"maxProperties";
"minProperties";
"required";
"dependentRequired";
"format";
]
let rec verbose_output_units ?(depth = 32) ?(dynamic_ref_targets = [])
?recursive_ref_target evaluator base_uri schema_path instance_path schema
instance all_errors =
if depth <= 0 then []
else
match schema with
| `Bool true -> []
| `Bool false ->
[ verbose_keyword_unit base_uri schema_path instance_path all_errors ]
| `Assoc pairs ->
let local_base_uri = schema_local_base evaluator base_uri pairs in
let recursive_ref_target =
recursive_ref_target_at evaluator local_base_uri pairs
recursive_ref_target
in
let dynamic_ref_targets =
if evaluator.config.dynamic_ref_enabled then
add_dynamic_resource_targets evaluator.registry local_base_uri
dynamic_ref_targets
else dynamic_ref_targets
in
if
List.mem_assoc "$ref" pairs && not evaluator.config.ref_siblings_apply
then
verbose_reference_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri local_base_uri schema_path
instance_path pairs instance all_errors
else
List.concat_map
(verbose_keyword_units_for_pair ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator local_base_uri schema_path
instance_path pairs instance all_errors)
pairs
| _ -> []
and verbose_child_units ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path schema instance all_errors =
verbose_output_units ~depth:(depth - 1) ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path schema
instance all_errors
and verbose_keyword_units_for_pair ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path pairs
instance all_errors (keyword, value) =
let keyword_path = add_path schema_path keyword in
if List.mem keyword verbose_direct_keyword_names then
[ verbose_keyword_unit base_uri keyword_path instance_path all_errors ]
else
match (keyword, value) with
| "$ref", `String _ | "$recursiveRef", `String _ | "$dynamicRef", `String _
->
verbose_reference_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri base_uri schema_path
instance_path
[ (keyword, value) ]
instance all_errors
| "properties", `Assoc prop_schemas ->
let children =
match instance with
| `Assoc instance_pairs ->
prop_schemas
|> List.concat_map (fun (name, prop_schema) ->
match List.assoc_opt name instance_pairs with
| Some prop_value ->
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path keyword_path name)
(add_path instance_path name)
prop_schema prop_value all_errors
| None -> [])
| _ -> []
in
[
verbose_keyword_unit base_uri keyword_path instance_path ~children
all_errors;
]
| "patternProperties", `Assoc pattern_schemas ->
let compiled_patterns =
pattern_schemas
|> List.filter_map (fun (pattern, schema) ->
match Regex.compile pattern with
| Ok re -> Some (pattern, re, schema)
| Error _ -> None)
in
let children =
match instance with
| `Assoc instance_pairs ->
instance_pairs
|> List.concat_map (fun (name, prop_value) ->
compiled_patterns
|> List.concat_map (fun (pattern, re, prop_schema) ->
if Regex.matches re name then
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path keyword_path pattern)
(add_path instance_path name)
prop_schema prop_value all_errors
else []))
| _ -> []
in
[
verbose_keyword_unit base_uri keyword_path instance_path ~children
all_errors;
]
| "additionalProperties", _ ->
[
verbose_additional_properties_unit base_uri schema_path instance_path
pairs instance all_errors;
]
| "items", ((`Assoc _ | `Bool _ | `List _) as item_schema) ->
[
verbose_items_unit ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path pairs item_schema
instance all_errors;
]
| "additionalItems", ((`Assoc _ | `Bool _) as schema) ->
verbose_additional_items_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
pairs schema instance all_errors
| "prefixItems", `List schemas ->
[
verbose_prefix_items_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
schemas instance all_errors;
]
| "contains", ((`Assoc _ | `Bool _) as contains_schema) ->
[
verbose_contains_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
contains_schema instance all_errors;
]
| "dependentSchemas", `Assoc schemas ->
[
verbose_dependent_schemas_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
schemas instance all_errors;
]
| "dependencies", `Assoc dependencies ->
verbose_dependencies_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
dependencies instance all_errors
| "propertyNames", ((`Assoc _ | `Bool _) as property_name_schema) ->
[
verbose_property_names_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
property_name_schema instance all_errors;
]
| "unevaluatedProperties", ((`Assoc _ | `Bool _) as schema) ->
[
verbose_unevaluated_properties_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
pairs schema instance all_errors;
]
| "unevaluatedItems", ((`Assoc _ | `Bool _) as schema) ->
[
verbose_unevaluated_items_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
pairs schema instance all_errors;
]
| ("allOf" | "anyOf" | "oneOf"), `List schemas ->
let children =
schemas |> list_indexed
|> List.concat_map (fun (index, subschema) ->
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path keyword_path (string_of_int index))
instance_path subschema instance all_errors)
in
[
verbose_keyword_unit base_uri keyword_path instance_path ~children
all_errors;
]
| "not", ((`Assoc _ | `Bool _) as subschema) ->
let children =
verbose_child_units ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri keyword_path instance_path subschema instance
all_errors
in
[
verbose_keyword_unit base_uri keyword_path instance_path ~children
all_errors;
]
| "if", ((`Assoc _ | `Bool _) as if_schema) ->
verbose_conditional_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
pairs if_schema instance all_errors
| "then", _ | "else", _ -> []
| _ -> []
and verbose_items_unit ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path pairs item_schema instance
all_errors =
let keyword_path = add_path schema_path "items" in
let children =
match (instance, item_schema) with
| `List items, `List schemas ->
items |> list_indexed
|> List.concat_map (fun (index, item) ->
if index < List.length schemas then
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path keyword_path (string_of_int index))
(add_path instance_path (string_of_int index))
(List.nth schemas index) item all_errors
else [])
| `List items, ((`Assoc _ | `Bool _) as schema) ->
let start =
if evaluator.draft_rank >= 2020 then
match List.assoc_opt "prefixItems" pairs with
| Some (`List schemas) -> List.length schemas
| _ -> 0
else 0
in
items |> list_indexed
|> List.concat_map (fun (index, item) ->
if index >= start then
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri keyword_path
(add_path instance_path (string_of_int index))
schema item all_errors
else [])
| _ -> []
in
verbose_keyword_unit base_uri keyword_path instance_path ~children all_errors
and verbose_prefix_items_unit ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path schemas instance all_errors =
let keyword_path = add_path schema_path "prefixItems" in
let children =
match instance with
| `List items ->
items |> list_indexed
|> List.concat_map (fun (index, item) ->
if index < List.length schemas then
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path keyword_path (string_of_int index))
(add_path instance_path (string_of_int index))
(List.nth schemas index) item all_errors
else [])
| _ -> []
in
verbose_keyword_unit base_uri keyword_path instance_path ~children all_errors
and verbose_additional_items_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path pairs
(additional_schema : Yojson.Safe.t) instance all_errors =
let keyword_path = add_path schema_path "additionalItems" in
match (instance, List.assoc_opt "items" pairs) with
| `List items, Some (`List item_schemas) ->
let additional_items =
items |> list_indexed
|> List.filter (fun (index, _) -> index >= List.length item_schemas)
in
let children =
match additional_schema with
| `Bool false ->
all_errors
|> List.filter (fun (error : Error.t) ->
error.schema_path = keyword_path
&& List.exists
(fun (index, _) ->
error.instance_path
= add_path instance_path (string_of_int index))
additional_items)
|> List.map (detailed_output_unit_of_error base_uri)
| `Bool true -> []
| `Assoc _ ->
additional_items
|> List.concat_map (fun (index, item) ->
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri keyword_path
(add_path instance_path (string_of_int index))
additional_schema item all_errors)
| _ -> []
in
[
verbose_keyword_unit base_uri keyword_path instance_path ~children
all_errors;
]
| _ -> []
and verbose_contains_unit ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path contains_schema instance
all_errors =
let keyword_path = add_path schema_path "contains" in
let children =
if errors_under keyword_path all_errors = [] then []
else
match instance with
| `List items ->
items |> list_indexed
|> List.concat_map (fun (index, item) ->
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri keyword_path
(add_path instance_path (string_of_int index))
contains_schema item all_errors)
| _ -> []
in
verbose_keyword_unit base_uri keyword_path instance_path ~children all_errors
and verbose_dependencies_unit ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path dependencies instance
all_errors =
let keyword_path = add_path schema_path "dependencies" in
let children =
match instance with
| `Assoc pairs ->
let property_dependency_errors =
all_errors
|> List.filter (fun (error : Error.t) ->
error.schema_path = keyword_path)
|> List.map (detailed_output_unit_of_error base_uri)
in
let schema_dependency_children =
dependencies
|> List.concat_map (fun (trigger, dependency) ->
match dependency with
| `List _ -> []
| dependency_schema when List.mem_assoc trigger pairs ->
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path keyword_path trigger)
instance_path dependency_schema instance all_errors
| _ -> [])
in
property_dependency_errors @ schema_dependency_children
| _ -> []
in
[
verbose_keyword_unit base_uri keyword_path instance_path ~children
all_errors;
]
and verbose_dependent_schemas_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path schemas
instance all_errors =
let keyword_path = add_path schema_path "dependentSchemas" in
let children =
match instance with
| `Assoc pairs ->
schemas
|> List.concat_map (fun (trigger, schema) ->
if List.mem_assoc trigger pairs then
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri
(add_path keyword_path trigger)
instance_path schema instance all_errors
else [])
| _ -> []
in
verbose_keyword_unit base_uri keyword_path instance_path ~children all_errors
and verbose_property_names_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path
property_name_schema instance all_errors =
let keyword_path = add_path schema_path "propertyNames" in
let children =
match instance with
| `Assoc pairs ->
pairs
|> List.concat_map (fun (name, _) ->
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri keyword_path
(add_path instance_path name)
property_name_schema (`String name) all_errors)
| _ -> []
in
verbose_keyword_unit base_uri keyword_path instance_path ~children all_errors
and verbose_evaluated_properties evaluator base_uri instance_path pairs instance
=
match instance with
| `Assoc instance_pairs ->
let properties =
match List.assoc_opt "properties" pairs with
| Some (`Assoc props) -> props
| _ -> []
in
let property_names = List.map fst properties in
let property_evaluated =
properties
|> List.filter_map (fun (name, schema) ->
match List.assoc_opt name instance_pairs with
| Some value
when schema_valid_at evaluator base_uri schema value
(add_path instance_path name) ->
Some name
| _ -> None)
in
let patterns =
match List.assoc_opt "patternProperties" pairs with
| Some (`Assoc pattern_schemas) ->
List.filter_map
(fun (pattern, schema) ->
match Regex.compile pattern with
| Ok re -> Some (pattern, re, schema)
| Error _ -> None)
pattern_schemas
| _ -> []
in
let pattern_evaluated =
instance_pairs
|> List.concat_map (fun (name, value) ->
patterns
|> List.filter_map (fun (_, re, schema) ->
if
Regex.matches re name
&& schema_valid_at evaluator base_uri schema value
(add_path instance_path name)
then Some name
else None))
in
let matched_by_known name =
List.mem name property_names
|| List.exists (fun (_, re, _) -> Regex.matches re name) patterns
in
let additional_evaluated =
match List.assoc_opt "additionalProperties" pairs with
| Some (`Bool true) ->
instance_pairs
|> List.filter_map (fun (name, _) ->
if matched_by_known name then None else Some name)
| Some (`Bool false) | None -> []
| Some schema ->
instance_pairs
|> List.filter_map (fun (name, value) ->
if matched_by_known name then None
else if
schema_valid_at evaluator base_uri schema value
(add_path instance_path name)
then Some name
else None)
in
List.fold_left
(fun acc name -> if List.mem name acc then acc else name :: acc)
[]
(property_evaluated @ pattern_evaluated @ additional_evaluated)
| _ -> []
and verbose_unevaluated_properties_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path pairs
schema instance all_errors =
let keyword_path = add_path schema_path "unevaluatedProperties" in
let evaluated =
verbose_evaluated_properties evaluator base_uri instance_path pairs instance
in
let children =
match instance with
| `Assoc instance_pairs ->
instance_pairs
|> List.concat_map (fun (name, value) ->
if List.mem name evaluated then []
else
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri keyword_path
(add_path instance_path name)
schema value all_errors)
| _ -> []
in
verbose_keyword_unit base_uri keyword_path instance_path ~children all_errors
and verbose_evaluated_items evaluator base_uri instance_path pairs instance =
match instance with
| `List items ->
let indexed = list_indexed items in
let add_unique_int value values =
if List.mem value values then values else value :: values
in
let prefix_evaluated, prefix_len =
match List.assoc_opt "prefixItems" pairs with
| Some (`List schemas) when evaluator.draft_rank >= 2020 ->
let evaluated =
indexed
|> List.filter_map (fun (index, item) ->
if
index < List.length schemas
&& schema_valid_at evaluator base_uri
(List.nth schemas index) item
(add_path instance_path (string_of_int index))
then Some index
else None)
in
(evaluated, Some (List.length schemas))
| _ -> ([], None)
in
let item_evaluated =
match List.assoc_opt "items" pairs with
| Some (`List schemas) ->
indexed
|> List.filter_map (fun (index, item) ->
if
index < List.length schemas
&& schema_valid_at evaluator base_uri (List.nth schemas index)
item
(add_path instance_path (string_of_int index))
then Some index
else None)
| Some ((`Assoc _ | `Bool _) as schema) ->
let start = match prefix_len with Some n -> n | None -> 0 in
indexed
|> List.filter_map (fun (index, item) ->
if
index >= start
&& schema_valid_at evaluator base_uri schema item
(add_path instance_path (string_of_int index))
then Some index
else None)
| _ -> []
in
let contains_evaluated =
match List.assoc_opt "contains" pairs with
| Some schema ->
indexed
|> List.filter_map (fun (index, item) ->
if
schema_valid_at evaluator base_uri schema item
(add_path instance_path (string_of_int index))
then Some index
else None)
| None -> []
in
List.fold_left
(fun acc index -> add_unique_int index acc)
[]
(prefix_evaluated @ item_evaluated @ contains_evaluated)
| _ -> []
and verbose_unevaluated_items_unit ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri schema_path instance_path pairs
schema instance all_errors =
let keyword_path = add_path schema_path "unevaluatedItems" in
let evaluated =
verbose_evaluated_items evaluator base_uri instance_path pairs instance
in
let children =
match instance with
| `List items ->
items |> list_indexed
|> List.concat_map (fun (index, item) ->
if List.mem index evaluated then []
else
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator base_uri keyword_path
(add_path instance_path (string_of_int index))
schema item all_errors)
| _ -> []
in
verbose_keyword_unit base_uri keyword_path instance_path ~children all_errors
and verbose_reference_units ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri local_base_uri schema_path instance_path pairs instance
all_errors =
let reference_unit keyword enabled acc =
if not enabled then acc
else
match List.assoc_opt keyword pairs with
| Some (`String ref_str) ->
let keyword_path = add_path schema_path keyword in
let resolved =
resolve_ref_uri evaluator base_uri local_base_uri
dynamic_ref_targets recursive_ref_target keyword ref_str
in
let children =
match
Registry.resolve_with_base_and_path evaluator.registry resolved
with
| Some (target_schema, target_base, target_path) ->
verbose_child_units ~depth ~dynamic_ref_targets
?recursive_ref_target evaluator target_base target_path
instance_path target_schema instance all_errors
| None -> []
in
acc
@ [
verbose_keyword_unit local_base_uri keyword_path instance_path
~children all_errors;
]
| _ -> acc
in
[] |> reference_unit "$ref" true
|> reference_unit "$recursiveRef" evaluator.config.recursive_ref_enabled
|> reference_unit "$dynamicRef" evaluator.config.dynamic_ref_enabled
and verbose_conditional_units ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri schema_path instance_path pairs if_schema instance
all_errors =
let if_path = add_path schema_path "if" in
let if_valid =
schema_valid_at evaluator base_uri if_schema instance instance_path
in
let if_children =
if if_valid then
verbose_child_units ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri if_path instance_path if_schema instance all_errors
else []
in
let if_units =
if if_valid then
[
verbose_keyword_unit base_uri if_path instance_path
~children:if_children all_errors;
]
else []
in
let branch_keyword = if if_valid then "then" else "else" in
let branch_units =
match List.assoc_opt branch_keyword pairs with
| Some ((`Assoc _ | `Bool _) as branch_schema) ->
let branch_path = add_path schema_path branch_keyword in
let children =
verbose_child_units ~depth ~dynamic_ref_targets ?recursive_ref_target
evaluator base_uri branch_path instance_path branch_schema instance
all_errors
in
[
verbose_keyword_unit base_uri branch_path instance_path ~children
all_errors;
]
| _ -> []
in
if_units @ branch_units
let schema_errors_at evaluator base_uri schema_path schema instance
instance_path =
let validator =
Compiler.compile evaluator.config evaluator.registry ~base_uri ~schema_path
schema
in
validator instance instance_path
let output_unit_list = function None -> [] | Some unit -> [ unit ]
let error_consumed_by consumed_paths (error : error) =
List.exists
(fun consumed_path -> path_has_prefix consumed_path error.schema_path)
consumed_paths
let detailed_keyword_unit base_uri keyword_path instance_path raw_errors
children =
let direct_error =
List.find_opt
(fun (error : Error.t) -> error.schema_path = keyword_path)
raw_errors
in
match (direct_error, children) with
| None, [] -> None
| Some error, [] -> Some (detailed_output_unit_of_error base_uri error)
| _, _ :: _ ->
let absolute_keyword_location =
absolute_keyword_location base_uri keyword_path
in
let error =
Option.map (fun (error : Error.t) -> error.message) direct_error
in
let instance_location =
match direct_error with
| Some error -> error.instance_path
| None -> instance_path
in
Some
(output_unit ~valid:false ~keyword_location:keyword_path
?absolute_keyword_location ~instance_location ?error ~errors:children
())
let rec detailed_output_units_for_schema ?(depth = 32) evaluator base_uri
schema_path instance_path schema instance raw_errors =
if depth <= 0 then
List.map (detailed_output_unit_of_error base_uri) raw_errors
else
let grouped_units, consumed_paths =
detailed_group_units ~depth evaluator base_uri schema_path instance_path
schema instance raw_errors
in
let fallback_units =
raw_errors
|> List.filter (fun error -> not (error_consumed_by consumed_paths error))
|> List.map (detailed_output_unit_of_error base_uri)
in
grouped_units @ fallback_units
and detailed_child_units ~depth evaluator base_uri schema_path instance_path
schema instance =
let raw_errors =
schema_errors_at evaluator base_uri schema_path schema instance
instance_path
in
detailed_output_units_for_schema ~depth:(depth - 1) evaluator base_uri
schema_path instance_path schema instance raw_errors
|> List.filter (fun unit -> path_has_prefix schema_path unit.keyword_location)
and detailed_group_units ~depth evaluator base_uri schema_path instance_path
schema instance raw_errors =
match schema with
| `Assoc pairs ->
let local_base_uri = schema_local_base evaluator base_uri pairs in
pairs
|> List.concat_map
(detailed_group_units_for_pair ~depth evaluator local_base_uri
schema_path instance_path pairs instance raw_errors)
|> fun units ->
let consumed_paths = List.map (fun unit -> unit.keyword_location) units in
(units, consumed_paths)
| _ -> ([], [])
and detailed_group_units_for_pair ~depth evaluator base_uri schema_path
instance_path pairs instance raw_errors (keyword, value) =
let keyword_path = add_path schema_path keyword in
let children =
match (keyword, value) with
| "properties", `Assoc prop_schemas ->
detailed_property_children ~depth evaluator base_uri keyword_path
instance_path prop_schemas instance
| "patternProperties", `Assoc pattern_schemas ->
detailed_pattern_property_children ~depth evaluator base_uri
keyword_path instance_path pattern_schemas instance
| "additionalProperties", ((`Assoc _ | `Bool _) as schema) ->
detailed_additional_property_children ~depth evaluator base_uri
schema_path keyword_path instance_path pairs schema instance
| "items", ((`Assoc _ | `Bool _ | `List _) as schema) ->
detailed_item_children ~depth evaluator base_uri schema_path
keyword_path instance_path pairs schema instance
| "prefixItems", `List schemas ->
detailed_prefix_item_children ~depth evaluator base_uri keyword_path
instance_path schemas instance
| "contains", ((`Assoc _ | `Bool _) as schema) ->
if errors_under keyword_path (flatten_errors raw_errors) = [] then []
else
detailed_contains_children ~depth evaluator base_uri keyword_path
instance_path schema instance
| "dependentSchemas", `Assoc schemas ->
detailed_dependent_schema_children ~depth evaluator base_uri
keyword_path instance_path schemas instance
| "propertyNames", ((`Assoc _ | `Bool _) as schema) ->
detailed_property_name_children ~depth evaluator base_uri keyword_path
instance_path schema instance
| "unevaluatedProperties", ((`Assoc _ | `Bool _) as schema) ->
detailed_unevaluated_property_children ~depth evaluator base_uri
keyword_path instance_path pairs schema instance
| "unevaluatedItems", ((`Assoc _ | `Bool _) as schema) ->
detailed_unevaluated_item_children ~depth evaluator base_uri
keyword_path instance_path pairs schema instance
| _ -> []
in
detailed_keyword_unit base_uri keyword_path instance_path raw_errors children
|> output_unit_list
and detailed_property_children ~depth evaluator base_uri keyword_path
instance_path prop_schemas instance =
match instance with
| `Assoc instance_pairs ->
prop_schemas
|> List.concat_map (fun (name, prop_schema) ->
match List.assoc_opt name instance_pairs with
| Some value ->
detailed_child_units ~depth evaluator base_uri
(add_path keyword_path name)
(add_path instance_path name)
prop_schema value
| None -> [])
| _ -> []
and detailed_pattern_property_children ~depth evaluator base_uri keyword_path
instance_path pattern_schemas instance =
let compiled_patterns =
pattern_schemas
|> List.filter_map (fun (pattern, schema) ->
match Regex.compile pattern with
| Ok re -> Some (pattern, re, schema)
| Error _ -> None)
in
match instance with
| `Assoc instance_pairs ->
instance_pairs
|> List.concat_map (fun (name, value) ->
compiled_patterns
|> List.concat_map (fun (pattern, re, schema) ->
if Regex.matches re name then
detailed_child_units ~depth evaluator base_uri
(add_path keyword_path pattern)
(add_path instance_path name)
schema value
else []))
| _ -> []
and detailed_additional_property_children ~depth evaluator base_uri _schema_path
keyword_path instance_path pairs schema instance =
match (instance, schema) with
| `Assoc instance_pairs, (`Assoc _ | `Bool true) ->
let property_names =
match List.assoc_opt "properties" pairs with
| Some (`Assoc props) -> List.map fst props
| _ -> []
in
let patterns =
match List.assoc_opt "patternProperties" pairs with
| Some (`Assoc pattern_schemas) ->
pattern_schemas
|> List.filter_map (fun (pattern, _) ->
match Regex.compile pattern with
| Ok re -> Some re
| Error _ -> None)
| _ -> []
in
let is_additional name =
not
(List.mem name property_names
|| List.exists (fun re -> Regex.matches re name) patterns)
in
instance_pairs
|> List.concat_map (fun (name, value) ->
if is_additional name then
detailed_child_units ~depth evaluator base_uri keyword_path
(add_path instance_path name)
schema value
else [])
| _, _ -> []
and detailed_item_children ~depth evaluator base_uri _schema_path keyword_path
instance_path pairs schema instance =
match (instance, schema) with
| `List items, `List schemas ->
items |> list_indexed
|> List.concat_map (fun (index, item) ->
if index < List.length schemas then
detailed_child_units ~depth evaluator base_uri
(add_path keyword_path (string_of_int index))
(add_path instance_path (string_of_int index))
(List.nth schemas index) item
else [])
| `List items, ((`Assoc _ | `Bool _) as item_schema) ->
let start =
if evaluator.draft_rank >= 2020 then
match List.assoc_opt "prefixItems" pairs with
| Some (`List schemas) -> List.length schemas
| _ -> 0
else 0
in
items |> list_indexed
|> List.concat_map (fun (index, item) ->
if index >= start then
detailed_child_units ~depth evaluator base_uri keyword_path
(add_path instance_path (string_of_int index))
item_schema item
else [])
| _ -> []
and detailed_prefix_item_children ~depth evaluator base_uri keyword_path
instance_path schemas instance =
match instance with
| `List items ->
items |> list_indexed
|> List.concat_map (fun (index, item) ->
if index < List.length schemas then
detailed_child_units ~depth evaluator base_uri
(add_path keyword_path (string_of_int index))
(add_path instance_path (string_of_int index))
(List.nth schemas index) item
else [])
| _ -> []
and detailed_contains_children ~depth evaluator base_uri keyword_path
instance_path schema instance =
match instance with
| `List items ->
items |> list_indexed
|> List.concat_map (fun (index, item) ->
detailed_child_units ~depth evaluator base_uri keyword_path
(add_path instance_path (string_of_int index))
schema item)
| _ -> []
and detailed_dependent_schema_children ~depth evaluator base_uri keyword_path
instance_path schemas instance =
match instance with
| `Assoc pairs ->
schemas
|> List.concat_map (fun (trigger, schema) ->
if List.mem_assoc trigger pairs then
detailed_child_units ~depth evaluator base_uri
(add_path keyword_path trigger)
instance_path schema instance
else [])
| _ -> []
and detailed_property_name_children ~depth evaluator base_uri keyword_path
instance_path schema instance =
match instance with
| `Assoc pairs ->
pairs
|> List.concat_map (fun (name, _) ->
detailed_child_units ~depth evaluator base_uri keyword_path
(add_path instance_path name)
schema (`String name))
| _ -> []
and detailed_unevaluated_property_children ~depth evaluator base_uri
keyword_path instance_path pairs schema instance =
let evaluated =
verbose_evaluated_properties evaluator base_uri instance_path pairs instance
in
match instance with
| `Assoc instance_pairs ->
instance_pairs
|> List.concat_map (fun (name, value) ->
if List.mem name evaluated then []
else
detailed_child_units ~depth evaluator base_uri keyword_path
(add_path instance_path name)
schema value)
| _ -> []
and detailed_unevaluated_item_children ~depth evaluator base_uri keyword_path
instance_path pairs schema instance =
let evaluated =
verbose_evaluated_items evaluator base_uri instance_path pairs instance
in
match instance with
| `List items ->
items |> list_indexed
|> List.concat_map (fun (index, item) ->
if List.mem index evaluated then []
else
detailed_child_units ~depth evaluator base_uri keyword_path
(add_path instance_path (string_of_int index))
schema item)
| _ -> []
let output_json evaluator format ~valid ~errors ~annotations instance =
match format with
| Flag -> `Assoc [ ("valid", `Bool valid) ]
| Basic ->
let root_unit =
output_unit ~valid ~keyword_location:Json_pointer.empty
~instance_location:Json_pointer.empty
~errors:
(List.concat_map
(basic_output_units_of_error evaluator.base_uri)
errors)
~annotations:(List.map output_unit_of_annotation annotations)
()
in
json_of_root_output_unit root_unit
| Detailed ->
let child_units =
detailed_output_units_for_schema evaluator evaluator.base_uri
Json_pointer.empty Json_pointer.empty evaluator.schema instance errors
in
let root_unit =
output_unit ~valid ~keyword_location:Json_pointer.empty
~instance_location:Json_pointer.empty ~errors:child_units
~annotations:(List.map output_unit_of_annotation annotations)
()
in
json_of_root_output_unit root_unit
| Verbose ->
let all_errors = flatten_errors errors in
let child_units =
verbose_output_units evaluator evaluator.base_uri Json_pointer.empty
Json_pointer.empty evaluator.schema instance all_errors
in
let fallback_errors =
List.concat_map (basic_output_units_of_error evaluator.base_uri) errors
in
let root_unit =
output_unit ~valid ~keyword_location:Json_pointer.empty
~instance_location:Json_pointer.empty ()
in
let root_unit =
match (child_units, annotations, valid) with
| _, _, false ->
{
root_unit with
errors =
(if child_units = [] then fallback_errors else child_units);
}
| _, _, true ->
{
root_unit with
annotations =
child_units @ List.map output_unit_of_annotation annotations;
}
in
json_of_root_output_unit root_unit
let evaluate evaluator instance =
let errors = evaluator.validator instance Json_pointer.empty in
let valid = errors = [] in
let annotations =
if valid then
collect_annotations evaluator evaluator.base_uri Json_pointer.empty
Json_pointer.empty evaluator.schema instance
else []
in
{
valid;
errors;
annotations;
output =
(fun format ->
output_json evaluator format ~valid ~errors ~annotations instance);
}
let compile_result_with_profile ~schema_dialect ~id_keyword
~allow_boolean_schemas ~ref_siblings_apply ~recursive_ref_enabled
~recursive_ref_target ~dynamic_ref_enabled ~dynamic_ref_targets
~select_config ~draft_rank keywords ?format_assertion ?base_uri ?retriever
schema_json =
let registry, config, input_base_uri =
registry_and_config_with_profile ~schema_dialect ~id_keyword
~allow_boolean_schemas ~ref_siblings_apply ~recursive_ref_enabled
~recursive_ref_target ~dynamic_ref_enabled ~dynamic_ref_targets
~select_config keywords ?format_assertion ?base_uri ?retriever schema_json
in
let validator =
Compiler.compile config registry ~base_uri:input_base_uri schema_json
in
let base_uri = effective_root_base ~id_keyword input_base_uri schema_json in
let compile_schema ?base_uri schema =
let base_uri =
match base_uri with Some uri -> uri | None -> input_base_uri
in
Compiler.compile config registry ~base_uri schema
in
{
validator;
schema = schema_json;
base_uri;
registry;
config;
id_keyword;
draft_rank;
compile_schema;
}
let compile_result_draft03 ?format_assertion ?base_uri ?retriever schema_json =
compile_result_with_profile ~schema_dialect:Registry.draft03_schema_dialect
~id_keyword:"id" ~allow_boolean_schemas:false ~ref_siblings_apply:false
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(fun config _ -> config)
~draft_rank:3 Draft03_keywords.all_keywords ?format_assertion ?base_uri
?retriever schema_json
let compile_result_draft04 ?format_assertion ?base_uri ?retriever schema_json =
compile_result_with_profile ~schema_dialect:Registry.draft04_schema_dialect
~id_keyword:"id" ~allow_boolean_schemas:false ~ref_siblings_apply:false
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(fun config _ -> config)
~draft_rank:4 Draft04_keywords.all_keywords ?format_assertion ?base_uri
?retriever schema_json
let compile_result_draft06 ?format_assertion ?base_uri ?retriever schema_json =
compile_result_with_profile ~schema_dialect:Registry.draft06_schema_dialect
~id_keyword:"$id" ~allow_boolean_schemas:true ~ref_siblings_apply:false
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(fun config _ -> config)
~draft_rank:6 Draft06_keywords.all_keywords ?format_assertion ?base_uri
?retriever schema_json
let compile_result_draft07 ?format_assertion ?base_uri ?retriever schema_json =
compile_result_with_profile ~schema_dialect:Registry.draft07_schema_dialect
~id_keyword:"$id" ~allow_boolean_schemas:true ~ref_siblings_apply:false
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(draft07_select_config ?retriever)
~draft_rank:7 Draft07_keywords.all_keywords ?format_assertion ?base_uri
?retriever schema_json
let compile_result_draft2019_09 ?format_assertion ?base_uri ?retriever
schema_json =
let keywords =
Draft2019_09_keywords.keywords_for_schema ?retriever schema_json
in
compile_result_with_profile
~schema_dialect:Registry.draft2019_09_schema_dialect ~id_keyword:"$id"
~allow_boolean_schemas:true ~ref_siblings_apply:true
~recursive_ref_enabled:true ~recursive_ref_target:None
~dynamic_ref_enabled:false ~dynamic_ref_targets:[]
~select_config:(draft2019_09_select_config ?retriever)
~draft_rank:2019 keywords ?format_assertion ?base_uri ?retriever schema_json
let compile_result_draft2020_12 ?format_assertion ?base_uri ?retriever
schema_json =
let keywords =
Draft2020_12_keywords.keywords_for_schema ?format_assertion ?retriever
schema_json
in
compile_result_with_profile
~schema_dialect:Registry.draft2020_12_schema_dialect ~id_keyword:"$id"
~allow_boolean_schemas:true ~ref_siblings_apply:true
~recursive_ref_enabled:false ~recursive_ref_target:None
~dynamic_ref_enabled:true ~dynamic_ref_targets:[]
~select_config:(draft2020_12_select_config ?retriever)
~draft_rank:2020 keywords ?format_assertion ?base_uri ?retriever schema_json
module Draft03 : LAYER = struct
let compile = compile_draft03 Draft03_keywords.all_keywords
let validate = run_validate
let is_valid = run_is_valid
let compile_result = compile_result_draft03
let evaluate = evaluate
let default_schema_uri = "http://json-schema.org/draft-03/schema"
let validate_schema =
validate_schema_with_profile ~schema_dialect:Registry.draft03_schema_dialect
~default_schema_uri
let is_valid_schema =
is_valid_schema_with_profile ~schema_dialect:Registry.draft03_schema_dialect
~default_schema_uri
end
module Draft04 : LAYER = struct
let compile = compile_draft04 Draft04_keywords.all_keywords
let validate = run_validate
let is_valid = run_is_valid
let compile_result = compile_result_draft04
let evaluate = evaluate
let default_schema_uri = "http://json-schema.org/draft-04/schema"
let validate_schema =
validate_schema_with_profile ~schema_dialect:Registry.draft04_schema_dialect
~default_schema_uri
let is_valid_schema =
is_valid_schema_with_profile ~schema_dialect:Registry.draft04_schema_dialect
~default_schema_uri
end
module Draft06 : LAYER = struct
let compile = compile_draft06 Draft06_keywords.all_keywords
let validate = run_validate
let is_valid = run_is_valid
let compile_result = compile_result_draft06
let evaluate = evaluate
let default_schema_uri = "http://json-schema.org/draft-06/schema"
let validate_schema =
validate_schema_with_profile ~schema_dialect:Registry.draft06_schema_dialect
~default_schema_uri
let is_valid_schema =
is_valid_schema_with_profile ~schema_dialect:Registry.draft06_schema_dialect
~default_schema_uri
end
module Draft07 : LAYER = struct
let compile = compile_draft07
let validate = run_validate
let is_valid = run_is_valid
let compile_result = compile_result_draft07
let evaluate = evaluate
let default_schema_uri = "http://json-schema.org/draft-07/schema"
let validate_schema =
validate_schema_with_profile ~schema_dialect:Registry.draft07_schema_dialect
~default_schema_uri
let is_valid_schema =
is_valid_schema_with_profile ~schema_dialect:Registry.draft07_schema_dialect
~default_schema_uri
end
module Draft2019_09 : LAYER = struct
let compile = compile_draft2019_09
let validate = run_validate
let is_valid = run_is_valid
let compile_result = compile_result_draft2019_09
let evaluate = evaluate
let default_schema_uri = "https://json-schema.org/draft/2019-09/schema"
let validate_schema =
validate_schema_with_profile
~schema_dialect:Registry.draft2019_09_schema_dialect ~default_schema_uri
let is_valid_schema =
is_valid_schema_with_profile
~schema_dialect:Registry.draft2019_09_schema_dialect ~default_schema_uri
end
module Draft2020_12 : LAYER = struct
let compile = compile_draft2020_12
let validate = run_validate
let is_valid = run_is_valid
let compile_result = compile_result_draft2020_12
let evaluate = evaluate
let default_schema_uri = "https://json-schema.org/draft/2020-12/schema"
let validate_schema =
validate_schema_with_profile
~schema_dialect:Registry.draft2020_12_schema_dialect ~default_schema_uri
let is_valid_schema =
is_valid_schema_with_profile
~schema_dialect:Registry.draft2020_12_schema_dialect ~default_schema_uri
end