You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| {{{nameInPascalCase}}} v -> [%to_yojson: {{{ datatypeWithEnum }}}] v
10
+
{{/composedSchemas.oneOf}}
11
+
12
+
(* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *)
13
+
14
+
let of_yojson json =
15
+
[
16
+
{{#composedSchemas.oneOf}}
17
+
[%of_yojson: {{{ datatypeWithEnum }}}] json
18
+
|> Stdlib.Result.to_option
19
+
|> Stdlib.Option.map (fun v -> {{{nameInPascalCase}}} v);
20
+
{{/composedSchemas.oneOf}}
21
+
]
22
+
|> Stdlib.List.filter_map (Fun.id)
23
+
|> function
24
+
| [t] -> Ok t
25
+
| [] -> Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}")
26
+
| ts -> let parsed_ts = ts
27
+
|> Stdlib.List.map show
28
+
|> Stdlib.String.concat " | "
29
+
in Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}: oneOf should only succeed on one parser, but the JSON was parsed into [" ^ parsed_ts ^ "]")
0 commit comments