Skip to content

Don't validate Yojson.Safe.t abstract type #263

@MisterDA

Description

@MisterDA

Yojson rename it's Yojson.Safe.json type to Yojson.Safe.t and deprecated the old type. It also removed the Yojson.Safe.validate_json and deliberately not introduced a new Yojson.Safe.validate_t. I have an atd document using the json type, and I'd like to validation for the values produced, but however I write it, I cannot get atd to turn off validation for that type: it always produces code that call the non-existent Yojson.Safe.validate_t function.

cat > test.atd <<EOF
type json <ocaml module="Yojson.Safe" t="t"> = abstract <ocaml valid="fun _x -> true">
type json' <ocaml module="Yojson.Safe" t="t"> = abstract <ocaml validator="fun _path _x -> None">
EOF
atdgen -v test.atd
ocamlfind ocamlc -o test.exe -linkpkg -package yojson,atdgen test_v.ml

produces

(* Auto-generated from "test.atd" *)
              [@@@ocaml.warning "-27-32-35-39"]

type json' = Yojson.Safe.t

type json = Yojson.Safe.t

let validate_json' = (
  (fun path x -> match ( fun _path _x -> None ) path x with | Some _ as err -> err | None -> (Yojson.Safe.validate_t) path x)
)
let validate_json = (
  (fun path x -> match ( fun path x ->
    let msg = "Failed check by fun _x -> true" in
    if (fun _x -> true) x then
      None
    else
      Some (Atdgen_runtime.Util.Validation.error ~msg path) ) path x with | Some _ as err -> err | None -> (Yojson.Safe.validate_t) path x)
)

and

File "test_v.ml", line 9, characters 91-113:
9 |   (fun path x -> match ( fun _x _y -> None ) path x with | Some _ as err -> err | None -> (Yojson.Safe.validate_t) path x)
                                                                                               ^^^^^^^^^^^^^^^^^^^^^^
Error: Unbound value Yojson.Safe.validate_t

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions