Skip to content

Commit

Permalink
Do not validate 'abstract' type by default
Browse files Browse the repository at this point in the history
  • Loading branch information
metanivek committed Jun 7, 2022
1 parent 65a4534 commit 92846ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions atdgen/src/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ let rec ocaml_of_expr_mapping (x : (Repr.t, _) mapping) : ocaml_expr =
`Name (s, List.map ocaml_of_expr_mapping l)
| Tvar (_, s) ->
`Tvar s
| Abstract _ -> `Name ("Yojson.Safe.t", [])
| _ -> assert false

and ocaml_of_variant_mapping x =
Expand Down
4 changes: 3 additions & 1 deletion atdgen/src/ov_emit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ let rec get_validator_name
| Bool (_, Bool, v)
| Int (_, Int _, v)
| Float (_, Float, v)
| String (_, String, v) ->
| String (_, String, v)
| Abstract (_, Abstract, v) ->
(match v with
(None, true) -> return_true_paren
| (Some s, true) -> s
Expand Down Expand Up @@ -202,6 +203,7 @@ let rec make_validator (x : ov_mapping) : Indent.t list =
| String _
| Name _
| External _
| Abstract _
| Tvar _ -> [ Line (get_validator_name x) ]
| Sum (_, a, Sum x, (v, shallow)) ->
Expand Down
17 changes: 10 additions & 7 deletions atdgen/src/ov_mapping.ml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ let rec mapping_of_expr
Float (loc, Float, (v an, true))
| "string" ->
String (loc, String, (v an, true))
| "abstract" ->
Abstract (loc, Abstract, (v an, true))
| s ->
let validator =
match v2 an x0 with
Expand Down Expand Up @@ -307,13 +309,14 @@ let def_of_atd is_shallow (loc, (name, param, an), x) =
let o =
match as_abstract x with
| Some (_, an2) ->
Ocaml.get_ocaml_module_and_t Validate name an
|> Option.map (fun (types_module, main_module, ext_name) ->
let args = List.map (fun s -> Tvar (loc, s)) param in
External (loc, name, args,
Ocaml.Repr.External (types_module, main_module, ext_name),
(Validate.get_validator an2, false))
)
(match Ocaml.get_ocaml_module_and_t Validate name an with
| None -> Some (mapping_of_expr is_shallow x)
| Some (types_module, main_module, ext_name) ->
let args = List.map (fun s -> Tvar (loc, s)) param in
Some (External (loc, name, args,
Ocaml.Repr.External (types_module, main_module, ext_name),
(Validate.get_validator an2, false))))

| None -> Some (mapping_of_expr is_shallow x)
in
{
Expand Down

0 comments on commit 92846ef

Please sign in to comment.