-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backfill @required on ChangeMessageVisibilityBatchRequestEntry.Visibi…
…lityTimeout
- Loading branch information
Showing
6 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,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" | ||
] | ||
} |
57 changes: 57 additions & 0 deletions
57
.../main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillRequiredTrait.java
This file contains 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,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())); | ||
} | ||
} |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.