package mcp-kit

  1. Overview
  2. Docs

Source file draft2019_09.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
(** Draft 2019-09 vocabulary — keyword compilers. *)

let all_keywords : Jsonschema_core.Compiler.keyword_compiler list =
  [
    Kw_type.compilers;
    Kw_numeric.compilers;
    Kw_string.compilers;
    Kw_array.draft2019_09_compilers;
    Kw_object.draft2019_09_compilers;
    Kw_logic.compilers;
    Kw_conditional.compilers;
    Kw_format.draft2019_09_compilers;
  ]
  |> List.flatten

let applicator_keywords : Jsonschema_core.Compiler.keyword_compiler list =
  [
    [
      Kw_array.compile_items;
      Kw_array.compile_additional_items;
      Kw_array.compile_contains_bounded;
      Kw_array.compile_unevaluated_items_simple;
    ];
    [
      Kw_object.compile_properties;
      Kw_object.compile_pattern_properties;
      Kw_object.compile_additional_properties;
      Kw_object.compile_property_names;
      Kw_object.compile_dependent_schemas;
      Kw_object.compile_unevaluated_properties_simple;
    ];
    Kw_logic.compilers;
    Kw_conditional.compilers;
  ]
  |> List.flatten

let validation_vocabulary_uri =
  "https://json-schema.org/draft/2019-09/vocab/validation"

let schema_declares_no_validation_vocabulary ?retriever schema_json =
  match (schema_json, retriever) with
  | `Assoc pairs, Some retrieve -> (
      match List.assoc_opt "$schema" pairs with
      | Some (`String schema_uri) -> (
          match retrieve (Uri.of_string schema_uri) with
          | Some (`Assoc meta_pairs) -> (
              match List.assoc_opt "$vocabulary" meta_pairs with
              | Some (`Assoc vocab) -> (
                  match List.assoc_opt validation_vocabulary_uri vocab with
                  | Some (`Bool true) -> false
                  | _ -> true)
              | _ -> false)
          | _ -> false)
      | _ -> false)
  | _ -> false

let keywords_for_schema ?retriever schema_json =
  if schema_declares_no_validation_vocabulary ?retriever schema_json then
    applicator_keywords
  else all_keywords