Skip to content

Commit

Permalink
codegen: Add backfilling boxed trait to S3Control API shape (#988)
Browse files Browse the repository at this point in the history
Adds backfilling @boxed trait to the S3Control ExpirationInDays shape.
  • Loading branch information
jasdel authored Dec 18, 2020
1 parent 3132eaa commit 033ce65
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2020 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.smithy.aws.go.codegen.customization;

import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
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.IntegerShape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.BoxTrait;
import software.amazon.smithy.utils.MapUtils;
import software.amazon.smithy.utils.SetUtils;

/**
* Integration that back fills the `boxed` traits to API shapes that were not decorated with the trait in the model.
*/
public class BackfillBoxTrait implements GoIntegration {
private static final Logger LOGGER = Logger.getLogger(BackfillBoxTrait.class.getName());

/**
* Map of service shape to Set of operation shapes that need to have this
* presigned url auto fill customization.
*/
public static final Map<ShapeId, Set<ShapeId>> SERVICE_TO_MEMBER_MAP = MapUtils.of(
ShapeId.from("com.amazonaws.s3control#AWSS3ControlServiceV20180820"), SetUtils.of(
ShapeId.from("com.amazonaws.s3control#S3ExpirationInDays")
));

/**
* /**
* Updates the API model to add additional members to the operation input shape that are needed for presign url
* customization.
*
* @param model API model
* @param settings Go codegen settings
* @return updated API model
*/
@Override
public Model preprocessModel(Model model, GoSettings settings) {
ShapeId serviceId = settings.getService();
if (!SERVICE_TO_MEMBER_MAP.containsKey(serviceId)) {
return model;
}
Model.Builder builder = model.toBuilder();

Set<ShapeId> shapeIds = SERVICE_TO_MEMBER_MAP.get(serviceId);
for (ShapeId shapeId : shapeIds) {
IntegerShape shape = model.expectShape(shapeId, IntegerShape.class);
if (shape.getTrait(BoxTrait.class).isPresent()) {
LOGGER.warning("BoxTrait is present in model and does not require backfill");
continue;
}
builder.addShape(shape.toBuilder()
.addTrait(new BoxTrait())
.build());
}

return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ software.amazon.smithy.aws.go.codegen.AwsSdkServiceId
software.amazon.smithy.aws.go.codegen.AwsRetryMiddlewareHelper
software.amazon.smithy.aws.go.codegen.AWSRequestIDRetriever
software.amazon.smithy.aws.go.codegen.AWSResponseErrorWrapper
software.amazon.smithy.aws.go.codegen.customization.BackfillBoxTrait
software.amazon.smithy.aws.go.codegen.customization.DynamoDBValidateResponseChecksum
software.amazon.smithy.aws.go.codegen.customization.S3UpdateEndpoint
software.amazon.smithy.aws.go.codegen.customization.APIGatewayAcceptHeader
Expand Down
2 changes: 1 addition & 1 deletion service/s3control/deserializers.go

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

4 changes: 2 additions & 2 deletions service/s3control/serializers.go

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

2 changes: 1 addition & 1 deletion service/s3control/types/types.go

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

0 comments on commit 033ce65

Please sign in to comment.