Skip to content

Commit

Permalink
generator: add support of $defs for json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Khady committed Feb 27, 2024
1 parent 1bdb379 commit 779674b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ let make_atd_of_schemas schemas =
let make_atd_of_jsonschema input =
let schema = Json_schema_j.schema_of_string input in
let root_type_name = Option.value ~default:"root" schema.title in
make_atd_of_schemas [ root_type_name, Obj schema ]
let defs =
match schema.defs with
| None -> []
| Some defs -> List.map (fun (name, schema) -> name, Obj schema) defs
in
make_atd_of_schemas ([ root_type_name, Obj schema ] @ defs)

let make_atd_of_openapi input =
let root = Openapi_j.root_of_string input in
Expand Down
2 changes: 2 additions & 0 deletions tests/smoke.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Generate ATD out of JSON Schema that contains defs
type json <ocaml module="Yojson.Basic" t="t"> = abstract
type int64 = int <ocaml repr="int64">

type name = string

type root = {
first_name: name;
last_name: name;
Expand Down

0 comments on commit 779674b

Please sign in to comment.