ahrefs / atd

Static types for JSON APIs
Other
308 stars 53 forks source link

atdgen: `int <ocaml repr="int64">` uses JSON strings instead of JSON numbers #402

Closed mjambon closed 4 months ago

mjambon commented 4 months ago

Solution: Use the opam package atdgen-runtime >= 2.12.0.

type int64 = int <ocaml repr="int64">

should be a JSON number. The <ocaml ...> annotation should not affect the JSON representation.

As of atdgen 2.15.0 and atdgen-runtime 2.11.0, such a type is serialized into a JSON string.

$ echo 'type int64 = int <ocaml repr="int64">' > bug.atd
$ atdgen -t bug.atd
$ atdgen -j -j-std bug.atd
$ cat bug.ml 
print_endline (Bug_j.string_of_int64 42L)
$ ocamlfind opt -o bug -package atdgen-runtime bug_t.mli bug_t.ml bug_j.mli bug_j.ml bug.ml -linkpkg
$ ./bug 
"42"

Instead, it should print:

42

I'm not sure where we are on the int64 support, between the reversion that occurred with 2.12.0 and #291 that was never merged.

I apologize for the confusing state of the tests for atdgen (atdgen/test). It could certainly be improved and simplified. Anyway, it looks like we should have test that checks that the JSON is how it should be.

mjambon commented 4 months ago

Update: the problem was with the runtime library atdgen-runtime. Version 2.11.0 has the problem. Versions 2.12.0 and 2.15.0 are fine.