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

Implement support for @caseName annotation #378

Closed
jdegoes opened this issue Oct 24, 2022 · 0 comments · Fixed by #429
Closed

Implement support for @caseName annotation #378

jdegoes opened this issue Oct 24, 2022 · 0 comments · Fixed by #429
Assignees

Comments

@jdegoes
Copy link
Member

jdegoes commented Oct 24, 2022

After #203 is completed, then each specified annotation may be implemented for each of the supported codecs for which it makes sense to support the annotation.

This ticket is to implement the @caseName annotation. This annotation, which may be applied to any case (subtype) of a sealed trait (enumeration), means to specify the "serialization" name of the case to which it is applied.

For example, maybe we wish the CreditCard subtype of PaymentMethod to be stored with a name of credit_card, rather than CreditCard, but we do not wish to name our Scala data type credit_card, because it is not idiomatic. This annotation would allow us to apply @caseName("credit_card") to the CreditCard data type, and then, the identity of the case would be credit_card rather than CreditCard (so if used in combination with @discriminatorName, would result in "type": "credit_card" in generated JSON, for example).

The main place where this new annotation should be used is in Schema auto-derivation. Right now, ZIO Schema will generate Schema.Case value together with an identity for the subtype for each case (subtype) of an enumeration (sealed trait). These term ids use the Scala case names (the names of the case classes that extend the sealed trait). But, in the presence of this annotation, they should instead use the specified name.

There are two ways to implement this ticket:

  1. Modifying the Scala 2 / Scala 3 macros to generate a different value for the case names, if this annotation is present.
  2. Post-processing the auto-generated Schema to incorporate changes brought about by annotations such as caseName.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

2 participants