package ppx_deriving_jsonschema

  1. Overview
  2. Docs
Jsonschema generator for ppx_deriving

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ppx_deriving_jsonschema-0.0.8.tbz
sha256=c5a2f8c1d906c1890bcde81aa149cc38e479878eb6c1c45a8455d03a95a07c2e
sha512=c0e661717244bf62132a21ef975db2720597b1d8013b0221c1d7db5adfc14928caf675c0f2fd89869ee6f4f96527599e556a0c123cd9dc7f65cad8f81de322ef

doc/src/ppx_deriving_jsonschema.runtime/ppx_deriving_jsonschema_runtime_primitives.ml.html

Source file ppx_deriving_jsonschema_runtime_primitives.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
module Common = struct
  type t = Ppx_deriving_jsonschema_runtime_classify.t
  let char_jsonschema : t = `Assoc [ "type", `String "string"; "minLength", `Int 1; "maxLength", `Int 1 ]
  let string_jsonschema : t = `Assoc [ "type", `String "string" ]
  let bool_jsonschema : t = `Assoc [ "type", `String "boolean" ]
  let float_jsonschema : t = `Assoc [ "type", `String "number" ]
  let int_jsonschema : t = `Assoc [ "type", `String "integer" ]
  let option_jsonschema (schema : t) : t =
    let is_basic_type ty = ty = "string" || ty = "number" || ty = "boolean" || ty = "integer" in
    match schema with
    | `Assoc (("type", `String ty) :: rest) when is_basic_type ty ->
      `Assoc (("type", `List [ `String ty; `String "null" ]) :: rest)
    | s -> `Assoc [ "anyOf", `List [ s; `Assoc [ "type", `String "null" ] ] ]
  let unit_jsonschema : t = `Assoc [ "type", `String "null" ]
  let list_jsonschema element_type : t = `Assoc [ "type", `String "array"; "items", element_type ]
  let array_jsonschema element_type : t = `Assoc [ "type", `String "array"; "items", element_type ]
end

module Yojson = struct
  include Common
  let int64_jsonschema : t = `Assoc [ "type", `String "integer" ]
end
[@@platform native]

module Melange_json = struct
  include Common
  let int64_jsonschema : t =
    `Assoc [ "type", `String "string"; "description", `String "int64 is represented as a string" ]
  let result_jsonschema (error_schema : t) (ok_schema : t) : t =
    `Assoc
      [
        ( "anyOf",
          `List
            [
              `Assoc
                [
                  "type", `String "array";
                  "prefixItems", `List [ `Assoc [ "const", `String "Error" ]; error_schema ];
                  "unevaluatedItems", `Bool false;
                  "minItems", `Int 1;
                ];
              `Assoc
                [
                  "type", `String "array";
                  "prefixItems", `List [ `Assoc [ "const", `String "Ok" ]; ok_schema ];
                  "unevaluatedItems", `Bool false;
                  "minItems", `Int 2;
                  "maxItems", `Int 2;
                ];
            ] );
      ]
end