Skip to content

A Hint on discriminated unions? #370

Answered by Baccata
Quafadas asked this question in Q&A
Discussion options

You must be logged in to vote

@Quafadas you have the @discriminated trait at the wrong level, or the type field in the json at the wrong level, depending on how you see things.

  1. You should remove the explicit type field you've added in the CfnDigraphNode shape in your smithy model. The type field in the json level is taken care of implicitly by smithy4s via the discriminated trait, without polluting the models. Smithy4s actually protects against the manual addition of the discriminator field, this is because giving the user access to the field would mean putting them at risk of creating invalid instances.
  2. The location of @discriminated("type") trait, as you've placed it, indicates that the json objects under payload s…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Quafadas
Comment options

@kubukoz
Comment options

Answer selected by Quafadas
Comment options

You must be logged in to vote
1 reply
@Quafadas
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants