Skip to content

Fix trait codegen for List or Map traits with annotations or Javadocs #2729

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

Merged
merged 3 commits into from
Aug 5, 2025

Conversation

joewyz
Copy link
Contributor

@joewyz joewyz commented Aug 1, 2025

Background

Trait codegen will generate duplicate @Deprecated annotation or Javadocs for the getValues() method if the trait is List or Map type.

For example, the following model:

/// This is my test list trait!!!
@trait
@deprecated(message: "Hey!", since: "Yesterday")
list MyListTrait {
    member: Integer
}

Trait codegen will produce the following code:

/**
 * This is my test list trait!!!
 *
 * @deprecated As of Yesterday. Hey!
 */
@Deprecated
@SmithyGenerated
public final class MyListTrait extends AbstractTrait implements ToSmithyBuilder<MyListTrait> {
    public static final ShapeId ID = ShapeId.from("example.traits#MyListTrait");

    private final List<Integer> values;

    private MyListTrait(Builder builder) {
        super(ID, builder.getSourceLocation());
        this.values = builder.values.copy();
    }

    //createNode()
    //fromNode()
    /**
     * This is my test list trait!!!
     *
     * @deprecated As of Yesterday. Hey!
     */
    @Deprecated
    public List<Integer> getValues() {
        return values;
    }
}

This PR fixed the above problem by add more checks in interceptors.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@joewyz joewyz requested a review from a team as a code owner August 1, 2025 23:14
@joewyz joewyz requested a review from sugmanue August 1, 2025 23:14
@joewyz joewyz requested review from milesziemer and removed request for sugmanue August 4, 2025 16:57
@joewyz joewyz merged commit 065a1eb into main Aug 5, 2025
9 checks passed
@joewyz joewyz deleted the joewyz/fix-trait-codegen-duplicate-deprecate-trait branch August 5, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants