You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature request:
I'd be interested in automatically generating a json schema (in the sense of https://json-schema.org) out of an OCaml type definition. A json schema is describing a subset of all jsons and can be seen as a json type or a validity criterion on a json structure. Say if I have an OCaml type ty = ... [@@deriving yojson], the json structures produced by ty_to_yojson, when applied to OCaml values of type ty, would be json structures abiding by the schema.
Ideally the schema would capture exactly the image of ty_to_yojson, but I expect the notion of json schema to be less expressive than OCaml's type system (e.g., I don't think json schemas have polymorphism and I think that in a json schema, all elements of JSON arrays must have the same type --which would be problematic for the encoding of OCaml's tuples as json arrays)...
...so for the moment what would be enough is producing a json schema that captures the image of ty_to_yojson for a simple class of OCaml types ty (no tuples, all constructors have "record-like / named arguments", etc), and perhaps producing a reasonable superset of that image when ty is outside that class.
I had hoped that the meta option of this deriver would do something along those lines, but it seems it does something much simpler.
Has anybody heard of a project doing what I'd like?
Json_schema in ocplib-json-typed has a representation of schemas (which are themselves jsons) but I see no deriver;
ATD offers its own notion of json type (from what I understand), whose expressivity may be well-suited to my use case, but the tool seems to offer a one way street towards OCaml code generation, while I need the reverse direction: producing json schemas from types in existing OCaml code;
ppx_yojson_conv seems to be the same kind of ppx deriver as ppx_deriving_yojson and, just like Milk, they both seem to offer value-level serialization/deserialization while I need type-level "serialization";
ppx_yojson does something different (though very useful).
The text was updated successfully, but these errors were encountered:
My understanding is that ppx_yojson_conv is a more recent library that supersedes ppx_deriving_yojson, and is more actively maintained. Given that your feature requires new developments, I would go ask the ppx_yojson_conv developers.
(I will edit the README here to formalize this recommandation.)
Feature request:
I'd be interested in automatically generating a json schema (in the sense of https://json-schema.org) out of an OCaml type definition. A json schema is describing a subset of all jsons and can be seen as a json type or a validity criterion on a json structure. Say if I have an OCaml type
ty = ... [@@deriving yojson]
, the json structures produced byty_to_yojson
, when applied to OCaml values of typety
, would be json structures abiding by the schema.Ideally the schema would capture exactly the image of
ty_to_yojson
, but I expect the notion of json schema to be less expressive than OCaml's type system (e.g., I don't think json schemas have polymorphism and I think that in a json schema, all elements of JSON arrays must have the same type --which would be problematic for the encoding of OCaml's tuples as json arrays)......so for the moment what would be enough is producing a json schema that captures the image of
ty_to_yojson
for a simple class of OCaml typesty
(no tuples, all constructors have "record-like / named arguments", etc), and perhaps producing a reasonable superset of that image whenty
is outside that class.I had hoped that the
meta
option of this deriver would do something along those lines, but it seems it does something much simpler.Has anybody heard of a project doing what I'd like?
The text was updated successfully, but these errors were encountered: