From 6df03fbdaa3bf07549633d833abefd4183b22b69 Mon Sep 17 00:00:00 2001 From: Egor Chemokhonenko Date: Fri, 29 Dec 2023 18:39:04 +0200 Subject: [PATCH] Some clean up --- lib/generator.ml | 8 ++------ lib/utils.ml | 4 ++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/generator.ml b/lib/generator.ml index 7621e8a..7e7153f 100644 --- a/lib/generator.ml +++ b/lib/generator.ml @@ -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 @@ -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); @@ -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); diff --git a/lib/utils.ml b/lib/utils.ml index 5973749..9c80728 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -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