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

Support open unions #1585

Open
1 task done
kubukoz opened this issue Sep 13, 2024 · 0 comments
Open
1 task done

Support open unions #1585

kubukoz opened this issue Sep 13, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@kubukoz
Copy link
Member

kubukoz commented Sep 13, 2024

Currently, we have a discrepancy between:

  • Smithy's documentation stating that union shapes should be considered open, and
  • Smithy4s's decision to prefer strict type safety and exhaustive pattern matching, as per Scala best practices.

We already support open enums, and the maintainers are in agreement that open unions should be supported in some way, as an opt-in mechanism.

The current thinking is that we should extend the alloy#jsonUnknown trait in Alloy to work on unions.

The desired semantics are as follows:

  • A union member can be marked with jsonUnknown. This is what we call the catch-all case from now on.
    • only one member can be marked with the trait (structurallyExclusive should do the job here)
    • To be confirmed: only Document or any document shape? Any document shape.
  • The deserialization process will wrap the entire document at the cursor in the catch-all case if it doesn't find a matching tag (in tagged unions), discriminator (in discriminated unions) or if neither member matches (in untagged unions)
  • Serialization of the catch-all case will write the entire document back.
  • This will be supported in JSON and Document (de)serialization only, as the trait s protocol-specific.

This would be a runtime-only change, meaning that codegen isn't going to be aware of the trait (only the interpreters/codecs would)

If I missed something, please let me know.

@kubukoz kubukoz added the enhancement New feature or request label Sep 13, 2024
@kubukoz kubukoz added this to the 0.19.0 milestone Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant