You can call jsonschema2atd and atdgen in your dune file to generate OCaml types and JSON serializers/deserializers from your JSON Schema or OpenAPI document:
; Add jsonschema2atd.runtime to have access to the oneOf serialization adapter (for variant unboxing).
(library
...
(libraries ... jsonschema2atd.runtime))
; Generate dashboard_gen.atd from the dashboard_types_gen.json OpenAPI document with jsonschema2atd.
(rule
(target dashboard_gen.atd)
; Store the generated .atd file in the code.
(mode promote)
(deps ../grok/dashboard_types_gen.json)
(action
(with-stdout-to
%{target}
(run
%{bin:jsonschema2atd} -f openapi
%{deps}))))
; Generate dashboard_gen_t.mli, dashboard_gen_t.ml, dashboard_gen_j.mli, and dashboard_gen_j.ml from dashboard_gen.atd with atdgen.
(rule
(targets
dashboard_gen_t.mli
dashboard_gen_t.ml
dashboard_gen_j.mli
dashboard_gen_j.ml)
(deps dashboard_gen.atd)
(action
(progn
(run %{bin:atdgen} -j -j-std -j-defaults %{deps})
(run %{bin:atdgen} -t %{deps}))))