Skip to content
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

Add a feature to allow any json in a variant #55

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

EmileTrotignon
Copy link
Contributor

Syntax is as follow :

type t =
| Other of Yojson.Basic.t [@allow_any]
| Foo
[@@deriving json]

Then, if the json j is invalid for type t, Other j is returned instead.

There is support for both runtime and js (although their Json type is different: is that an issue ? We could introduce a [%json] extension that translates to Js.Json.t in Js and Yojson.Basic.t in runtime if its an issue.)

As a bonus, I improved an error message that slipped through in my error message PR. Because its only on JS I did not find it with my cram tests.

As a bonus : imrpove of the last two unhelpful error message
@EmileTrotignon
Copy link
Contributor Author

EmileTrotignon commented Feb 7, 2025

I also moved the common folder inside the native one. The reason for that is that then I can use it with include subdirs, which enables merlin inside it, which is very useful for developing.

using copy_files means that merlin does not work inside these files.

@EmileTrotignon
Copy link
Contributor Author

Something similar exists in atdgen, it only allows extra tags instead of any json. I think allowing any json is a good idea, especially because we have structured types for json so we can easily check afterward if its tag-shapped.

Copy link
Member

@anmonteiro anmonteiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense, no strong opinions

@EmileTrotignon
Copy link
Contributor Author

Hey @anmonteiro I have added the label you asked, and remove the stray comment. Any other change required ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants