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

Generalize the option to always output optional fields that are set to the default value (~field : ... syntax) #354

Open
mjambon opened this issue Oct 2, 2023 · 0 comments
Labels
enhancement feature request Big and small feature requests target:python Issues related to the Python backend (atdpy) target:typescript Issues related to the TypeScript backend (atdts)

Comments

@mjambon
Copy link
Collaborator

mjambon commented Oct 2, 2023

To reduce breakage when an optional record field becomes required, an implementation of an ATD interface can output optional fields even though they have the default value. It allows future implementations that read old data or data produced by an old implementation in which the field used to be optional.

This applies to the ~ syntax for optional fields with a default but not to the ? syntax which are optional fields without a default or equivalently whose default is null/None. The main use of ~ is for lists and booleans where the default is obvious:

type t = {
  ~items: item list;
  ~enable_foo: bool;
}

A valid JSON representation for a record of type t is {}. It has the advantage of being compact. Forcing the output of default values would instead produce the following JSON object:

{
  "items": [],
  "enable_foo": false
}

Such an option is already supported by atdgen in the form of -j-defaults. There is demand for having it across all backends (especially Python and TypeScript). Alternatively, this can be made the default or the only behavior.

@mjambon mjambon added enhancement feature request Big and small feature requests target:python Issues related to the Python backend (atdpy) target:typescript Issues related to the TypeScript backend (atdts) labels Oct 2, 2023
@mjambon mjambon changed the title Generalize the option to "always output optional fields defined with a default" (~field : ... syntax) Generalize the option to "always output optional fields that are set to the default value" (~field : ... syntax) Oct 2, 2023
@mjambon mjambon changed the title Generalize the option to "always output optional fields that are set to the default value" (~field : ... syntax) Generalize the option to always output optional fields that are set to the default value (~field : ... syntax) Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature request Big and small feature requests target:python Issues related to the Python backend (atdpy) target:typescript Issues related to the TypeScript backend (atdts)
Projects
None yet
Development

No branches or pull requests

1 participant