Open
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Handle Unions with "type" members
Motivation and Context
When we generate Union shapes, we always add a special, SDK generated Type type member to the Pojo. The type member is a Union specific enum that is used as a type discriminator allowing customers (and internal code) to check which variant of the union is set and avoid unsafe casting. If the modeled type has a member named Type then this conflicts with our internally added Type field, causing the build to fail.
Given the following C2J Union definition:
We will generate:
Modifications
We introduce a new getVariableName method that takes the name and the parentShape. The parentShape argument is required for us to limit the scope of the reserved words - specifically “type” should only be considered a reserved word for members in a union. This limits the blast radius of the change, ensuring that it is non-breaking for existing services.
The new getVariableName(String name, Shape parentShape) uses the existing isDisallowedNameForShape method, which does correctly consider “type” a reserved word for Union parentShapes.
Is this change breaking?
No - because we limit checking “type” as a reserved word to Unions only, no existing cases will change. Any existing model that has a union member named “type” does not currently build. Changing the variable name does NOT change the serialization or deserialization code - they will still use “type” - it is only the name of the member that is changed.
Is this change in-line with other SDKs/smithy recommendations?
Yes - Smithy based codegen uses the concept of Symbols with SymbolProviders and SymbolWriters (See: Decoupling Codegen with Symbols) which automatically support handling of “reserved words”. Smithy recommends limiting reserved word handling to the most minimal context:
Reserved words handling should be as granular as possible. If a symbol is only reserved in certain contexts, then that word should only be treated as reserved in that context.
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License