Giter Club home page Giter Club logo

jsonschema2atd's Introduction

jsonschema2atd

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

Installation

The package is available on opam.

opam install jsonschema2atd

If you wish to install the development version you can do so 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

  • Base types
  • Records
  • Nullable
  • String enums
  • Integer enums
  • Other primitive enums
  • Refs (OpenAPI format)
  • OneOf (Only serialization is supported)
  • not
  • anyOf
  • allOf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.