Don't validate `Yojson.Safe.t` abstract type
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 352
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the shown test.atd, atdgen command, and test_v.ml compilation. Inspect the generated validators and the atdgen handling of abstract OCaml types and their valid or validator attributes. Done means generated code for Yojson.Safe.t no longer calls the nonexistent Yojson.Safe.validate_t and the requested validation behavior compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100