Skip to content

Commit

Permalink
Some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ixzzd committed Dec 29, 2023
1 parent d6ee0bd commit 6df03fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ let make_atd_default_value enum json_value =

let nullable = Printf.sprintf "%s nullable"

let nonempty_list_opt = function
| [] -> None
| non_empty_list -> Some non_empty_list

let merge_all_of schema =
match schema.all_of with
| None -> schema
Expand All @@ -84,7 +80,7 @@ let merge_all_of schema =
| first :: _ -> Some first
in
let merge_lists get_fn = schemas |> List.map get_fn |> List.flatten in
let merge_opt_lists get_fn = schemas |> List.filter_map get_fn |> List.flatten |> nonempty_list_opt in
let merge_opt_lists get_fn = schemas |> List.filter_map get_fn |> List.flatten |> Utils.nonempty_list_opt in
{
schema with
schema = take_first_opt (fun schema -> schema.schema);
Expand All @@ -100,7 +96,7 @@ let merge_all_of schema =
|> List.filter_map (fun schema -> schema.enum)
|> Utils.shortest_list
|> Option.value ~default:[]
|> nonempty_list_opt;
|> Utils.nonempty_list_opt;
max_length = take_first_opt (fun schema -> schema.max_length);
min_length = take_first_opt (fun schema -> schema.min_length);
pattern = take_first_opt (fun schema -> schema.pattern);
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ let hd_opt = function
| first :: _ -> Some first

let shortest_list lists = lists |> List.sort (fun a b -> compare (List.length a) (List.length b)) |> hd_opt

let nonempty_list_opt = function
| [] -> None
| non_empty_list -> Some non_empty_list

0 comments on commit 6df03fb

Please sign in to comment.