Skip to content

Commit

Permalink
Make from Vs module keyword also parametrizable
Browse files Browse the repository at this point in the history
  • Loading branch information
smondet committed Dec 4, 2024
1 parent dcf1757 commit ed9925e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
7 changes: 5 additions & 2 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ let main =
)
$ Arg.(value (flag (info [ "avoid-dangling-refs" ] ~doc:"Convert dangling refs to json.")))
$ Arg.(
let keyword = enum [ "module", `Module; "from", `From ] in
value
(opt (pair ~sep:':' string string) Generator.default_state.json_ocaml_type
(info [ "json-ocaml-type" ] ~docv:"MODULE.PATH:TYPE-NAME" ~doc:"Use an alternate Mod.type for `json`.")
(opt (t3 ~sep:':' keyword string string) Generator.default_state.json_ocaml_type
(info [ "json-ocaml-type" ] ~docv:"KEYWORD:MODULE.PATH:TYPE-NAME"
~doc:"Use an alternate Mod.type for `json`, e.g. from:My_mod.Submod:json_type."
)
)
)
)
Expand Down
15 changes: 10 additions & 5 deletions lib/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type state = {
protect_against_duplicates : string list ref option;
toplevel_types : [ `All | `Only of string list ];
avoid_dangling_refs : bool;
json_ocaml_type : string * string;
json_ocaml_type : [ `From | `Module ] * string * string;
}

let default_state =
Expand All @@ -16,7 +16,7 @@ let default_state =
protect_against_duplicates = None;
toplevel_types = `All;
avoid_dangling_refs = false;
json_ocaml_type = "Yojson.Basic", "t";
json_ocaml_type = `Module, "Yojson.Basic", "t";
}

let record_field_name _state str =
Expand Down Expand Up @@ -297,13 +297,18 @@ let process_schemas state (schemas : (string * schema or_ref) list) =
[] schemas

let base state from =
let module_path, type_t = state.json_ocaml_type in
let keyword, module_path, type_t = state.json_ocaml_type in
sprintf
{|(* Generated by jsonschema2atd from %s *)
type json <ocaml module="%s" t="%s"> = abstract
type json <ocaml %s="%s" t="%s"> = abstract
type int64 = int <ocaml repr="int64">
|}
from module_path type_t
from
( match keyword with
| `From -> "from"
| `Module -> "module"
)
module_path type_t

let make_atd_of_schemas state schemas =
let schemas =
Expand Down

0 comments on commit ed9925e

Please sign in to comment.