-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow arguments to adapters #184
Labels
feature request
Big and small feature requests
target:ocaml
Issues related to the OCaml backend (atdgen)
Comments
It seems reasonable to me. Keep in mind that json adapters are a relatively recent feature. There are a few things to take into account:
|
Great! Your first suggested syntax is what I had in mind, I agree the escaping problem is annoying but that it'd be best to start with that and perhaps improve in the future. I'll try to dive in and see if I can come up with something. |
Implemented by #232 |
mjambon
added a commit
to mjambon/opam-repository
that referenced
this issue
May 18, 2022
…n-codec-runtime and atd (2.7.0) CHANGES: * Add ability to specify JSON/OCaml adapter with the arbitrary code using `<json adapter.to_ocaml="..." adapter.from_ocaml="...">` (ahrefs/atd#184). * atdcat: add option `-jsonschema-no-additional-properties` for JSON Schema output to specify that JSON objects may not have extra properties (ahrefs/atd#293, ahrefs/atd#294). * atdcat: add `title` field to JSON Schema output containing the name of root type (ahrefs/atd#294). * atdcat: add command-line option to choose the version of JSON Schema to target. Options are the latest version "Draft 2020-12" and the previous version "Draft 2019-09" (ahrefs/atd#294). * ATD language: the `abstract` built-in can now be used like any other type to hold untyped data, if the implementation supports it. The supported targets so far are OCaml/JSON (atdgen), Python (atdpy), TypeScript (atdts), JSON Schema (atdcat) (ahrefs/atd#295).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
feature request
Big and small feature requests
target:ocaml
Issues related to the OCaml backend (atdgen)
[Feature Request]
[Bear with me, as I'm new to yojson/atd and OCaml in general]
I find adapters to be critical when working with external json structures, which I presume is a very common use case. The ability to pass arguments to adapters would make them much more flexible, readable within the .atd context, and allow for reuse and sharing of adapters.
Two use-case examples:
Atdgen_runtime.Json_adapter.Type_field
to take "type" field key as an argument{"a": 1, "b": 2, "c": 3}
when lifting with"body", ["a"]
would become{"a": 1, "body": {"b": 2, "c": 3}}
-- it'd be great if i could pass those arguments in the .atd file.Does that sound reasonable at all?
The text was updated successfully, but these errors were encountered: