ahrefs / atd

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

atdgen: support for wrapped keys for object repr in melange #403

Open danielmercier opened 3 months ago

danielmercier commented 3 months ago

This PR implements support for wrapped keys when using <json repr="object">:

As a simple example:

type t =
   ( string wrap <ocaml t="int" wrap="int_of_string" unwrap="string_of_int">
   * int) list <json repr="object">

Really unsure if this is the correct approach as re-using the encoder/decoder for the name is the simplest solution I found. This emulates what is done in oj_emit.ml. But this changes the Encode/Decode APIs

mjambon commented 2 months ago

This seems like an unusual need. Wouldn't it be best served by using an adapter that rewrites the JSON object into an array of pairs? I'm worried about the maintenance burden, atdgen being already very complicated.