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.ml.html

Source file ppx_deriving_jsonschema_runtime.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
let schema_version = "https://json-schema.org/draft/2020-12/schema"

type t = Ppx_deriving_jsonschema_runtime_classify.t

let classify = Ppx_deriving_jsonschema_runtime_classify.classify
let declassify = Ppx_deriving_jsonschema_runtime_classify.declassify

let json_schema ?id ?title ?description ?definitions types =
  let fields =
    match types with
    | `Assoc fields -> fields
    | _ -> []
  in
  let metadata =
    List.filter_map
      (fun x -> x)
      [
        Some ("$schema", `String schema_version);
        (match id with
        | None -> None
        | Some id -> Some ("$id", `String id));
        (match title with
        | None -> None
        | Some title -> Some ("title", `String title));
        (match description with
        | None -> None
        | Some description -> Some ("description", `String description));
        (match definitions with
        | None -> None
        | Some defs -> Some ("$defs", `Assoc defs));
      ]
  in
  `Assoc (metadata @ fields)

module Primitives = Ppx_deriving_jsonschema_runtime_primitives