From da11d7e1daa3ff669ea621230c4ed130e73e4ae0 Mon Sep 17 00:00:00 2001 From: Luc Talatinian <102624213+lucix-aws@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:18:04 -0400 Subject: [PATCH] backfill @required on ChangeMessageVisibilityBatchRequestEntry.VisibilityTimeout (#2767) --- .../3a3fee5b50bb49bda3226e0b2622885e.json | 8 +++ .../customization/BackfillRequiredTrait.java | 57 +++++++++++++++++++ ...mithy.go.codegen.integration.GoIntegration | 1 + .../attributevalue/go_module_metadata.go | 2 +- service/sqs/serializers.go | 2 +- service/sqs/types/types.go | 2 + 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .changelog/3a3fee5b50bb49bda3226e0b2622885e.json create mode 100644 codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillRequiredTrait.java diff --git a/.changelog/3a3fee5b50bb49bda3226e0b2622885e.json b/.changelog/3a3fee5b50bb49bda3226e0b2622885e.json new file mode 100644 index 00000000000..47cd4fa0a85 --- /dev/null +++ b/.changelog/3a3fee5b50bb49bda3226e0b2622885e.json @@ -0,0 +1,8 @@ +{ + "id": "3a3fee5b-50bb-49bd-a322-6e0b2622885e", + "type": "bugfix", + "description": "Fix issue where SDK could not send a VisibilityTimeout of 0 in a ChangeMessageVisibilityBatchRequestEntry.", + "modules": [ + "service/sqs" + ] +} diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillRequiredTrait.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillRequiredTrait.java new file mode 100644 index 00000000000..3ebdf0b28d7 --- /dev/null +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillRequiredTrait.java @@ -0,0 +1,57 @@ +package software.amazon.smithy.aws.go.codegen.customization; + +import static java.util.stream.Collectors.toSet; + +import java.util.Arrays; +import java.util.Map; +import java.util.Set; +import software.amazon.smithy.go.codegen.GoSettings; +import software.amazon.smithy.go.codegen.integration.GoIntegration; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.traits.RequiredTrait; +import software.amazon.smithy.model.transform.ModelTransformer; + +/** + * Adds the @required trait to inputs that have @default, but lack of serialization of their zero value causes issues. + * + * If a shape is listed here there should generally be an upstreaming effort with the service team to fix. Link issues + * in comments (or internal ticket IDs) where available. + */ +public class BackfillRequiredTrait implements GoIntegration { + private static final Map> toBackfill = Map.ofEntries( + serviceToShapeIds("com.amazonaws.sqs#AmazonSQS", + // https://github.com/aws/aws-sdk/issues/527 + "com.amazonaws.sqs#ChangeMessageVisibilityBatchRequestEntry$VisibilityTimeout") + ); + + private boolean mustPreprocess(ShapeId service) { + return toBackfill.containsKey(service); + } + + @Override + public Model preprocessModel(Model model, GoSettings settings) { + var serviceId = settings.getService(); + return mustPreprocess(serviceId) + ? backfillRequired(model, toBackfill.get(serviceId)) + : model; + } + + private Model backfillRequired(Model model, Set shapes) { + return ModelTransformer.create() + .mapShapes(model, (shape) -> shapes.contains(shape.getId()) ? withRequired(shape) : shape); + } + + private Shape withRequired(Shape shape) { + return Shape.shapeToBuilder(shape) + .addTrait(new RequiredTrait()) + .build(); + } + + private static Map.Entry> serviceToShapeIds(String serviceId, String... shapeIds) { + return Map.entry( + ShapeId.from(serviceId), + Arrays.stream(shapeIds).map(ShapeId::from).collect(toSet())); + } +} \ No newline at end of file diff --git a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration index cafa1e2a3f3..90f15c70e4c 100644 --- a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration +++ b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration @@ -84,3 +84,4 @@ software.amazon.smithy.aws.go.codegen.customization.AccountIDEndpointRouting software.amazon.smithy.aws.go.codegen.customization.RetryModeUserAgent software.amazon.smithy.aws.go.codegen.customization.RequestCompressionUserAgent software.amazon.smithy.aws.go.codegen.customization.s3.ExpressUserAgent +software.amazon.smithy.aws.go.codegen.customization.BackfillRequiredTrait diff --git a/feature/dynamodbstreams/attributevalue/go_module_metadata.go b/feature/dynamodbstreams/attributevalue/go_module_metadata.go index 7a81fb94f5b..f4c8ccb3bb1 100644 --- a/feature/dynamodbstreams/attributevalue/go_module_metadata.go +++ b/feature/dynamodbstreams/attributevalue/go_module_metadata.go @@ -3,4 +3,4 @@ package attributevalue // goModuleVersion is the tagged release for this module -const goModuleVersion = "1.14.3" +const goModuleVersion = "1.15.0" diff --git a/service/sqs/serializers.go b/service/sqs/serializers.go index d93605345ee..90d8492958d 100644 --- a/service/sqs/serializers.go +++ b/service/sqs/serializers.go @@ -1340,7 +1340,7 @@ func awsAwsjson10_serializeDocumentChangeMessageVisibilityBatchRequestEntry(v *t ok.String(*v.ReceiptHandle) } - if v.VisibilityTimeout != 0 { + { ok := object.Key("VisibilityTimeout") ok.Integer(v.VisibilityTimeout) } diff --git a/service/sqs/types/types.go b/service/sqs/types/types.go index 5dade2c0d71..78aca9b8031 100644 --- a/service/sqs/types/types.go +++ b/service/sqs/types/types.go @@ -50,6 +50,8 @@ type ChangeMessageVisibilityBatchRequestEntry struct { ReceiptHandle *string // The new value (in seconds) for the message's visibility timeout. + // + // This member is required. VisibilityTimeout int32 noSmithyDocumentSerde