Fix trait codegen for list with uniqueitems trait#2706
Merged
Conversation
Contributor
|
Let's make sure that we keep ordering of maps and sets of traits. That means to use a |
cb31fad to
145cc45
Compare
sugmanue
reviewed
Jul 30, 2025
...egen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java
Outdated
Show resolved
Hide resolved
...it-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/GetterGenerator.java
Outdated
Show resolved
Hide resolved
...it-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ToNodeGenerator.java
Outdated
Show resolved
Hide resolved
...it-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ToNodeGenerator.java
Outdated
Show resolved
Hide resolved
...it-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ToNodeGenerator.java
Outdated
Show resolved
Hide resolved
...it-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/ToNodeGenerator.java
Outdated
Show resolved
Hide resolved
...esources/software/amazon/smithy/traitcodegen/test/lists/nested-uniqueitems-list-trait.smithy
Outdated
Show resolved
Hide resolved
...egen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java
Outdated
Show resolved
Hide resolved
sugmanue
approved these changes
Jul 31, 2025
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.
Background
The current trait codegen is generating incorrect code for list with
@uniqueItems. We useSetto represent this kind of list in generated Java code but some part of code still generateListrelated code.For example, the following model:
will generate incorrect
fromNodemethod because it still useCollection.toList()Similarly, if we have a list of unique items in a structure:
The generated Java code also failed because
fromNodedid not convertListtoSetandgetMemberOrEmptyreturnedemptyListThis PR fixed the above problems.
Update 7/29/2025
We decided to change the stream style from for loop style to maintain the insertion order of set and map.
The generated code for nested set would be:
The generated code for nested map would be:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.