Ahrefs has released jsonschema2atd, a cli tool to convert an OpenAPI or Json Schema specification into an atd file.
Quite a lot of api out there are now publishing some kind of spec for their expected input our output. It’s often done through a a JSON Schema or OpenAPI document. The goal of this tool is to save time for large api by doing a mechanical translation to an atd file instead of writing all the types by hand.
Unfortunately the world is kind of a mess. Most of the specs we have seen are not following a specific version of openapi/jsonschema but contain a bit of everything. jsonschema2atd does its best to do the right thing, but there are probably cases that aren’t covered.
The generated code might also not be optimal. It often deserves some hand cleanup and a bit of renaming. Hopefully it still gives a good head start.
Thanks to Egor Chemokhonenko for this work.
The code is available at GitHub - ahrefs/jsonschema2atd: Generate ATD types from a JSON schema / OpenAPI document
And there is a package that is published on opam jsonschema2atd 0.0.2 (latest) · OCaml Package