package jsonschema2atd

  1. Overview
  2. Docs
Generate ATD types out of JSON Schema and OpenAPI document

Install

Dune Dependency

Authors

Maintainers

Sources

0.0.1.tar.gz
md5=dcdbf453fbfab9a1fe41966b69823c3b
sha512=b6ab5b78fee8fb41a7da867bcd11b54d92228e4798572aa7714aa59fc983a79998ddb176153755b6ca772ae5b38efef2e2f8a76459d165298455688bf55c6f83

Description

Generate ATD types out of JSON Schema and OpenAPI document

Published: 10 Jan 2024

README

jsonschema2atd

Generate an ATD file from a JSON Schema / OpenAPI document.

Installation

Install the package and dependencies with:

make install

Usage

Generate an ATD file from a JSON Schema:

jsonschema2atd ../path-to-jsonschema.json

Generate an ATD file from an OpenAPI document:

jsonschema2atd --format openapi ../path-to-openapi.json

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}))))

ToDo

  • [X] Base types

  • [X] Records

  • [X] Nullable

  • [X] String enums

  • [ ] Integer enums

  • [ ] Other primitive enums

  • [X] Refs (OpenAPI format)

  • [X] OneOf (Only serialization is supported)

  • [ ] not

  • [ ] anyOf

  • [X] allOf

Dependencies (6)

  1. yojson
  2. dune-build-info
  3. cmdliner >= "1.1.0"
  4. atdgen >= "2.7"
  5. ocaml >= "4.10"
  6. dune >= "3.0"

Dev Dependencies (4)

  1. ounit2 with-test
  2. odoc with-doc
  3. ocamlformat with-dev-setup & = "0.24.1"
  4. ocaml-lsp-server with-dev-setup

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.