|
| 1 | +(* Auto-generated from "variant_attr.atd" by atdml. *) |
| 2 | + |
| 3 | +type status = |
| 4 | + | Active [@deriving.ord.ignore] |
| 5 | + | Inactive |
| 6 | + | Pending of (int [@deriving.ord.ignore]) |
| 7 | + |
| 8 | +val status_of_yojson : Yojson.Safe.t -> status |
| 9 | +val yojson_of_status : status -> Yojson.Safe.t |
| 10 | +val status_of_json : string -> status |
| 11 | +val json_of_status : status -> string |
| 12 | + |
| 13 | +module Status : sig |
| 14 | + type nonrec t = status |
| 15 | + val of_yojson : Yojson.Safe.t -> t |
| 16 | + val to_yojson : t -> Yojson.Safe.t |
| 17 | + val of_json : string -> t |
| 18 | + val to_json : t -> string |
| 19 | +end |
| 20 | + |
| 21 | +--- ml --- |
| 22 | +(* Auto-generated from "variant_attr.atd" by atdml. *) |
| 23 | +[@@@ocaml.warning "-27-32-33-35-39"] |
| 24 | + |
| 25 | +(* Inlined runtime — no external dependency needed. *) |
| 26 | +module Atdml_runtime = struct |
| 27 | + let bad_type expected_type x = |
| 28 | + Printf.ksprintf failwith "expected %s, got: %s" |
| 29 | + expected_type (Yojson.Safe.to_string x) |
| 30 | + |
| 31 | + let bad_sum type_name x = |
| 32 | + Printf.ksprintf failwith "invalid variant for type '%s': %s" |
| 33 | + type_name (Yojson.Safe.to_string x) |
| 34 | + |
| 35 | + let missing_field type_name field_name = |
| 36 | + Printf.ksprintf failwith "missing field '%s' in object of type '%s'" |
| 37 | + field_name type_name |
| 38 | + |
| 39 | + let bool_of_yojson = function |
| 40 | + | `Bool b -> b |
| 41 | + | x -> bad_type "bool" x |
| 42 | + |
| 43 | + let yojson_of_bool b = `Bool b |
| 44 | + |
| 45 | + let int_of_yojson = function |
| 46 | + | `Int n -> n |
| 47 | + | x -> bad_type "int" x |
| 48 | + |
| 49 | + let yojson_of_int n = `Int n |
| 50 | + |
| 51 | + let float_of_yojson = function |
| 52 | + | `Float f -> f |
| 53 | + | `Int n -> Float.of_int n |
| 54 | + | x -> bad_type "float" x |
| 55 | + |
| 56 | + let yojson_of_float f = `Float f |
| 57 | + |
| 58 | + let string_of_yojson = function |
| 59 | + | `String s -> s |
| 60 | + | x -> bad_type "string" x |
| 61 | + |
| 62 | + let yojson_of_string s = `String s |
| 63 | + |
| 64 | + let unit_of_yojson = function |
| 65 | + | `Null -> () |
| 66 | + | x -> bad_type "null" x |
| 67 | + |
| 68 | + let yojson_of_unit () = `Null |
| 69 | + |
| 70 | + let list_of_yojson f = function |
| 71 | + | `List xs -> List.map f xs |
| 72 | + | x -> bad_type "array" x |
| 73 | + |
| 74 | + let yojson_of_list f xs = `List (List.map f xs) |
| 75 | + |
| 76 | + let option_of_yojson f = function |
| 77 | + | `String "None" -> None |
| 78 | + | `List [`String "Some"; x] -> Some (f x) |
| 79 | + | x -> bad_type "option" x |
| 80 | + |
| 81 | + let yojson_of_option f = function |
| 82 | + | None -> `String "None" |
| 83 | + | Some x -> `List [`String "Some"; f x] |
| 84 | + |
| 85 | + let nullable_of_yojson f = function |
| 86 | + | `Null -> None |
| 87 | + | x -> Some (f x) |
| 88 | + |
| 89 | + let yojson_of_nullable f = function |
| 90 | + | None -> `Null |
| 91 | + | Some x -> f x |
| 92 | + |
| 93 | + (* Returns true iff the list has strictly more than [n] elements, |
| 94 | + without traversing past element n+1. *) |
| 95 | + let rec list_length_gt n = function |
| 96 | + | _ :: rest -> if n = 0 then true else list_length_gt (n - 1) rest |
| 97 | + | [] -> false |
| 98 | + |
| 99 | + let assoc_of_yojson f = function |
| 100 | + | `Assoc pairs -> List.map (fun (k, v) -> (k, f v)) pairs |
| 101 | + | x -> bad_type "object" x |
| 102 | + |
| 103 | + let yojson_of_assoc f xs = |
| 104 | + `Assoc (List.map (fun (k, v) -> (k, f v)) xs) |
| 105 | +end |
| 106 | + |
| 107 | +type status = |
| 108 | + | Active [@deriving.ord.ignore] |
| 109 | + | Inactive |
| 110 | + | Pending of (int [@deriving.ord.ignore]) |
| 111 | + |
| 112 | +let status_of_yojson (x : Yojson.Safe.t) : status = |
| 113 | + match x with |
| 114 | + | `String "Active" -> Active |
| 115 | + | `String "Inactive" -> Inactive |
| 116 | + | `List [`String "Pending"; v] -> Pending (Atdml_runtime.int_of_yojson v) |
| 117 | + | _ -> Atdml_runtime.bad_sum "status" x |
| 118 | + |
| 119 | +let yojson_of_status (x : status) : Yojson.Safe.t = |
| 120 | + match x with |
| 121 | + | Active -> `String "Active" |
| 122 | + | Inactive -> `String "Inactive" |
| 123 | + | Pending v -> `List [`String "Pending"; Atdml_runtime.yojson_of_int v] |
| 124 | + |
| 125 | +let status_of_json s = |
| 126 | + status_of_yojson (Yojson.Safe.from_string s) |
| 127 | + |
| 128 | +let json_of_status x = |
| 129 | + Yojson.Safe.to_string (yojson_of_status x) |
| 130 | + |
| 131 | +module Status = struct |
| 132 | + type nonrec t = status |
| 133 | + let of_yojson = status_of_yojson |
| 134 | + let to_yojson = yojson_of_status |
| 135 | + let of_json = status_of_json |
| 136 | + let to_json = json_of_status |
| 137 | +end |
| 138 | + |
0 commit comments