Skip to content
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

backfill @required on ChangeMessageVisibilityBatchRequestEntry.VisibilityTimeout #2767

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading