Repository navigation
Carry Java-only customizations as codegen traits in Smithy codegen #7450
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
Fred1155
merged 2 commits into
feature/master/smithy-migration
from
bole/smithy_residual_customizations
Oct 19, 2026
+975
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
82 changes: 82 additions & 0 deletions
82
codegen/src/main/java/software/amazon/awssdk/codegen/smithy/SmithyCodegenTraits.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.codegen.smithy; | ||
|
|
||
| import software.amazon.awssdk.codegen.model.intermediate.MemberModel; | ||
| import software.amazon.awssdk.codegen.naming.NamingStrategy; | ||
| import software.amazon.awssdk.codegen.naming.ShapeInfo; | ||
| import software.amazon.awssdk.codegen.smithy.traits.AlternateBeanPropertyNameTrait; | ||
| import software.amazon.awssdk.codegen.smithy.traits.DeprecatedNameTrait; | ||
| import software.amazon.awssdk.codegen.smithy.traits.EnumConstantNameTrait; | ||
| import software.amazon.awssdk.codegen.smithy.traits.IgnoreDataTypeConversionFailuresTrait; | ||
| import software.amazon.awssdk.codegen.smithy.traits.SyntheticTrait; | ||
| import software.amazon.awssdk.utils.StringUtils; | ||
| import software.amazon.smithy.model.shapes.MemberShape; | ||
| import software.amazon.smithy.model.shapes.Shape; | ||
|
|
||
| /** | ||
| * Applies the codegen traits that carry Java-only customizations (see {@code software.amazon.awssdk.codegen.smithy | ||
| * .traits}) to the intermediate model, setting the same fields C2J's {@code AddShapes} sets. | ||
| */ | ||
| final class SmithyCodegenTraits { | ||
|
|
||
| private SmithyCodegenTraits() { | ||
| } | ||
|
|
||
| /** | ||
| * Read from the member's target shape, as C2J marks the added SDK shape rather than the member. | ||
| */ | ||
| static void applySynthetic(MemberModel memberModel, Shape targetShape) { | ||
| memberModel.setSynthetic(targetShape.hasTrait(SyntheticTrait.class)); | ||
| } | ||
|
|
||
| static void applyAlternateBeanPropertyName(MemberModel memberModel, MemberShape member) { | ||
| member.getTrait(AlternateBeanPropertyNameTrait.class).ifPresent( | ||
| t -> memberModel.setAdditionalBeanStyleSetterName(String.format("set%s", t.getValue()))); | ||
| } | ||
|
|
||
| static void applyIgnoreDataTypeConversionFailures(MemberModel memberModel, MemberShape member) { | ||
| if (member.hasTrait(IgnoreDataTypeConversionFailuresTrait.class)) { | ||
| memberModel.ignoreDataTypeConversionFailures(true); | ||
| } | ||
| } | ||
|
|
||
| static void applyDeprecatedName(MemberModel memberModel, MemberShape member, NamingStrategy namingStrategy, | ||
| ShapeInfo parentCtx, ShapeInfo shapeCtx) { | ||
| String deprecatedName = member.getTrait(DeprecatedNameTrait.class) | ||
| .map(DeprecatedNameTrait::getValue) | ||
| .orElse(null); | ||
| if (StringUtils.isBlank(deprecatedName)) { | ||
| return; | ||
| } | ||
| memberModel.setDeprecatedName(deprecatedName); | ||
| memberModel.setDeprecatedFluentGetterMethodName( | ||
| namingStrategy.getFluentGetterMethodName(deprecatedName, parentCtx, shapeCtx)); | ||
| memberModel.setDeprecatedFluentSetterMethodName( | ||
| namingStrategy.getFluentSetterMethodName(deprecatedName, parentCtx, shapeCtx)); | ||
| memberModel.setDeprecatedBeanStyleSetterMethodName( | ||
| namingStrategy.getBeanStyleSetterMethodName(deprecatedName, parentCtx, shapeCtx)); | ||
| } | ||
|
|
||
| /** | ||
| * Read from an enum value, not a structure member. Falls back to the name derived from the value. | ||
| */ | ||
| static String enumConstantName(MemberShape enumMember, String value, NamingStrategy namingStrategy) { | ||
| return enumMember.getTrait(EnumConstantNameTrait.class) | ||
| .map(EnumConstantNameTrait::getValue) | ||
| .orElseGet(() -> namingStrategy.getEnumValueName(value)); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...ain/java/software/amazon/awssdk/codegen/smithy/traits/AlternateBeanPropertyNameTrait.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.codegen.smithy.traits; | ||
|
|
||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.smithy.model.SourceLocation; | ||
| import software.amazon.smithy.model.shapes.ShapeId; | ||
| import software.amazon.smithy.model.traits.StringTrait; | ||
|
|
||
| /** | ||
| * {@code software.amazon.awssdk.codegen#alternateBeanPropertyName}: the generated class gets an extra bean-style | ||
| * setter named {@code set} followed by this value. Replaces the {@code customization.config} setting of the same name. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class AlternateBeanPropertyNameTrait extends StringTrait { | ||
|
|
||
| public static final ShapeId ID = ShapeId.from("software.amazon.awssdk.codegen#alternateBeanPropertyName"); | ||
|
|
||
| public AlternateBeanPropertyNameTrait(String value, SourceLocation sourceLocation) { | ||
| super(ID, value, sourceLocation); | ||
| } | ||
|
|
||
| public AlternateBeanPropertyNameTrait(String value) { | ||
| this(value, SourceLocation.NONE); | ||
| } | ||
|
|
||
| /** | ||
| * Registered in {@code META-INF/services} so Smithy builds this class when it loads the trait. | ||
| */ | ||
| public static final class Provider extends StringTrait.Provider<AlternateBeanPropertyNameTrait> { | ||
| public Provider() { | ||
| super(ID, AlternateBeanPropertyNameTrait::new); | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
codegen/src/main/java/software/amazon/awssdk/codegen/smithy/traits/DeprecatedNameTrait.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.codegen.smithy.traits; | ||
|
|
||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.smithy.model.SourceLocation; | ||
| import software.amazon.smithy.model.shapes.ShapeId; | ||
| import software.amazon.smithy.model.traits.StringTrait; | ||
|
|
||
| /** | ||
| * {@code software.amazon.awssdk.codegen#deprecatedName}: the member's name before a rename. The generated class keeps | ||
| * deprecated accessors under this name. Replaces {@code existingNameDeprecated} in {@code customization.config}. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class DeprecatedNameTrait extends StringTrait { | ||
|
|
||
| public static final ShapeId ID = ShapeId.from("software.amazon.awssdk.codegen#deprecatedName"); | ||
|
|
||
| public DeprecatedNameTrait(String value, SourceLocation sourceLocation) { | ||
| super(ID, value, sourceLocation); | ||
| } | ||
|
|
||
| public DeprecatedNameTrait(String value) { | ||
| this(value, SourceLocation.NONE); | ||
| } | ||
|
|
||
| /** | ||
| * Registered in {@code META-INF/services} so Smithy builds this class when it loads the trait. | ||
| */ | ||
| public static final class Provider extends StringTrait.Provider<DeprecatedNameTrait> { | ||
| public Provider() { | ||
| super(ID, DeprecatedNameTrait::new); | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...gen/src/main/java/software/amazon/awssdk/codegen/smithy/traits/EnumConstantNameTrait.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.codegen.smithy.traits; | ||
|
|
||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.smithy.model.SourceLocation; | ||
| import software.amazon.smithy.model.shapes.ShapeId; | ||
| import software.amazon.smithy.model.traits.StringTrait; | ||
|
|
||
| /** | ||
| * {@code software.amazon.awssdk.codegen#enumConstantName}: the Java enum constant name for an enum member, used instead | ||
| * of the name derived from its value. Replaces {@code emitEnumName} in {@code customization.config}. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class EnumConstantNameTrait extends StringTrait { | ||
|
|
||
| public static final ShapeId ID = ShapeId.from("software.amazon.awssdk.codegen#enumConstantName"); | ||
|
|
||
| public EnumConstantNameTrait(String value, SourceLocation sourceLocation) { | ||
| super(ID, value, sourceLocation); | ||
| } | ||
|
|
||
| public EnumConstantNameTrait(String value) { | ||
| this(value, SourceLocation.NONE); | ||
| } | ||
|
|
||
| /** | ||
| * Registered in {@code META-INF/services} so Smithy builds this class when it loads the trait. | ||
| */ | ||
| public static final class Provider extends StringTrait.Provider<EnumConstantNameTrait> { | ||
| public Provider() { | ||
| super(ID, EnumConstantNameTrait::new); | ||
| } | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...a/software/amazon/awssdk/codegen/smithy/traits/IgnoreDataTypeConversionFailuresTrait.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.codegen.smithy.traits; | ||
|
|
||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.smithy.model.node.Node; | ||
| import software.amazon.smithy.model.node.ObjectNode; | ||
| import software.amazon.smithy.model.shapes.ShapeId; | ||
| import software.amazon.smithy.model.traits.AnnotationTrait; | ||
|
|
||
| /** | ||
| * {@code software.amazon.awssdk.codegen#ignoreDataTypeConversionFailures}: the unmarshaller ignores a value that cannot | ||
| * be converted to the member's type. Replaces the {@code customization.config} setting of the same name. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class IgnoreDataTypeConversionFailuresTrait extends AnnotationTrait { | ||
|
|
||
| public static final ShapeId ID = ShapeId.from("software.amazon.awssdk.codegen#ignoreDataTypeConversionFailures"); | ||
|
|
||
| public IgnoreDataTypeConversionFailuresTrait(ObjectNode node) { | ||
| super(ID, node); | ||
| } | ||
|
|
||
| public IgnoreDataTypeConversionFailuresTrait() { | ||
| this(Node.objectNode()); | ||
| } | ||
|
|
||
| /** | ||
| * Registered in {@code META-INF/services} so Smithy builds this class when it loads the trait. | ||
| */ | ||
| public static final class Provider extends AnnotationTrait.Provider<IgnoreDataTypeConversionFailuresTrait> { | ||
| public Provider() { | ||
| super(ID, IgnoreDataTypeConversionFailuresTrait::new); | ||
| } | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
codegen/src/main/java/software/amazon/awssdk/codegen/smithy/traits/SyntheticTrait.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.codegen.smithy.traits; | ||
|
|
||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.smithy.model.node.Node; | ||
| import software.amazon.smithy.model.node.ObjectNode; | ||
| import software.amazon.smithy.model.shapes.ShapeId; | ||
| import software.amazon.smithy.model.traits.AnnotationTrait; | ||
|
|
||
| /** | ||
| * {@code software.amazon.awssdk.codegen#synthetic}: a shape added for SDK use only. Members that target it are not | ||
| * marshalled. Marks the shapes that {@code customSdkShapes} in {@code customization.config} adds. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class SyntheticTrait extends AnnotationTrait { | ||
|
|
||
| public static final ShapeId ID = ShapeId.from("software.amazon.awssdk.codegen#synthetic"); | ||
|
|
||
| public SyntheticTrait(ObjectNode node) { | ||
| super(ID, node); | ||
| } | ||
|
|
||
| public SyntheticTrait() { | ||
| this(Node.objectNode()); | ||
| } | ||
|
|
||
| /** | ||
| * Registered in {@code META-INF/services} so Smithy builds this class when it loads the trait. | ||
| */ | ||
| public static final class Provider extends AnnotationTrait.Provider<SyntheticTrait> { | ||
| public Provider() { | ||
| super(ID, SyntheticTrait::new); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there might be a small gap here. MetadataModifiersProcessor has two halves. postprocess applies contentType (now wired up). preprocess applies customServiceMetadata.protocol by overwriting ServiceMetadata.protocols — and this chain only ever calls postprocess, so on the Smithy path protocol is silently ignored. The only user in our services of protocol is Kinesis - but could potentially impact custom internal services....
I'd lean towards a fail fast check: throw in SmithyIntermediateModelPostprocessor.create when customServiceMetadata.protocol is non-null on the Smithy path (with a message pointing at addTraits + protocol traits which are the correct (and now supported) smithy way to handle this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this one, I have another PR #7442 to apply this preprocessing just for kinesis. And the old CBOR protocol has no Smithy trait..