ahrefs / ahrefs/atd

Don't validate `Yojson.Safe.t` abstract type

Open
#263 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first time issue packaging
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.