Skip to content

Commit

Permalink
backfill @required on ChangeMessageVisibilityBatchRequestEntry.Visibi…
Browse files Browse the repository at this point in the history
…lityTimeout
  • Loading branch information
lucix-aws committed Aug 30, 2024
1 parent 00ce6de commit e2c7899
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changelog/3a3fee5b50bb49bda3226e0b2622885e.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
Original file line number Diff line number Diff line change
@@ -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<ShapeId, Set<ShapeId>> 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<ShapeId> 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<ShapeId, Set<ShapeId>> serviceToShapeIds(String serviceId, String... shapeIds) {
return Map.entry(
ShapeId.from(serviceId),
Arrays.stream(shapeIds).map(ShapeId::from).collect(toSet()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/sqs/serializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions service/sqs/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2c7899

Please sign in to comment.