From 779674b57a7cb7c8b14a16b97b4135d2a4e37743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20Roch=C3=A9?= Date: Tue, 27 Feb 2024 11:37:39 +0100 Subject: [PATCH] generator: add support of $defs for json schema --- lib/generator.ml | 7 ++++++- tests/smoke.t | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/generator.ml b/lib/generator.ml index 4f6a692..df097b8 100644 --- a/lib/generator.ml +++ b/lib/generator.ml @@ -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 diff --git a/tests/smoke.t b/tests/smoke.t index a73a6c8..c99866e 100644 --- a/tests/smoke.t +++ b/tests/smoke.t @@ -50,6 +50,8 @@ Generate ATD out of JSON Schema that contains defs type json = abstract type int64 = int + type name = string + type root = { first_name: name; last_name: name;