codec: let open Json.Codec in cleanup across hermest + oci + stripe
Extend the encodings-skill cleanup to three more codec-heavy files,
using the accessor-functions idiom for records whose field names
clash with `Json.Codec.mem_map`.
The pattern: when a record has fields like `id` or `name` that also
exist in `mem_map`, OCaml's record disambiguation under
`let open Json.Codec in` would resolve `t.id` to `mem_map.id`. Hoist
the field accessors above the open, annotated only where needed:
let id (t : t) = t.id (* `id` clashes -> annotation needed *)
let name (t : t) = t.name (* `name` clashes -> annotation needed *)
let other t = t.other (* unique field -> no annotation *)
Then the codec body uses `~enc:id` / `~enc:name` / `~enc:other` and
the open is harmless. The `.mli` hides accessors by signature.
Files changed:
- ocaml-atp/hermest/lib/lexicon_types.ml (220 usages, 15 codec defs +
12 mutually-recursive `and X_json_lazy` defs): each body opens
`Json.Codec`. The lazy block building `type_def_json` annotates
`(String s : type_def)` / `(Array s : type_def)` / `(Object s :
type_def)` because `Json.Codec.t`'s GADT carries the same variant
names. The `enc_case` match is rewritten as `let enc_case (td :
type_def) = match td with ...` so subsequent constructor patterns
resolve to `type_def` rather than `Json.Codec.t`. `def_entry_json`
and `lexicon_doc_json` also use `(s : ...)` annotations because
their records carry `name` / `id` fields.
- ocaml-oci/lib/spec/config.ml (102 usages, 8 codec defs): opens
applied to every body. `Docker.t` carries an `id` field; hoisted
17 field accessors so `~enc:id`, `~enc:parent`, etc. read cleanly
and the long `Object.opt_mem` chain shrinks dramatically.
- ocaml-stripe/lib/stripe.ml (64 usages, 8 codec defs): every
Customer/Product/Price/Subscription/Checkout/Portal/Webhook record
has `id` (and most have `name`). Hoisted accessors per module.
The trivial `let metadata_jsont = Json.Codec.Object.as_string_map
Json.Codec.string` stays qualified -- not worth a wrapper for a
single combinator call.