Skip to content

Commit 5f2f70b

Browse files
authored
fix(client-s3): remove int validation of object size type (#2775)
1 parent 299cbbb commit 5f2f70b

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

clients/client-s3/protocols/Aws_restXml.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13814,7 +13814,7 @@ const deserializeAws_restXml_Object = (output: any, context: __SerdeContext): _O
1381413814
contents.ETag = __expectString(output["ETag"]);
1381513815
}
1381613816
if (output["Size"] !== undefined) {
13817-
contents.Size = __strictParseInt32(output["Size"]) as number;
13817+
contents.Size = __strictParseLong(output["Size"]) as number;
1381813818
}
1381913819
if (output["StorageClass"] !== undefined) {
1382013820
contents.StorageClass = __expectString(output["StorageClass"]);
@@ -13902,7 +13902,7 @@ const deserializeAws_restXmlObjectVersion = (output: any, context: __SerdeContex
1390213902
contents.ETag = __expectString(output["ETag"]);
1390313903
}
1390413904
if (output["Size"] !== undefined) {
13905-
contents.Size = __strictParseInt32(output["Size"]) as number;
13905+
contents.Size = __strictParseLong(output["Size"]) as number;
1390613906
}
1390713907
if (output["StorageClass"] !== undefined) {
1390813908
contents.StorageClass = __expectString(output["StorageClass"]);
@@ -14004,7 +14004,7 @@ const deserializeAws_restXmlPart = (output: any, context: __SerdeContext): Part
1400414004
contents.ETag = __expectString(output["ETag"]);
1400514005
}
1400614006
if (output["Size"] !== undefined) {
14007-
contents.Size = __strictParseInt32(output["Size"]) as number;
14007+
contents.Size = __strictParseLong(output["Size"]) as number;
1400814008
}
1400914009
return contents;
1401014010
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.smithy.aws.typescript.codegen;
17+
18+
import java.util.Map;
19+
import java.util.Set;
20+
import java.util.logging.Logger;
21+
import software.amazon.smithy.build.PluginContext;
22+
import software.amazon.smithy.model.Model;
23+
import software.amazon.smithy.model.shapes.LongShape;
24+
import software.amazon.smithy.model.shapes.ShapeId;
25+
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
26+
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
27+
import software.amazon.smithy.utils.MapUtils;
28+
import software.amazon.smithy.utils.OptionalUtils;
29+
import software.amazon.smithy.utils.SetUtils;
30+
import software.amazon.smithy.utils.SmithyInternalApi;
31+
32+
/**
33+
* Transform the S3 object size member from an integer to a long.
34+
*/
35+
@SmithyInternalApi
36+
public final class AddS3ObjectSizeMemberShapeType implements TypeScriptIntegration {
37+
private static final Logger LOGGER = Logger.getLogger(AddS3ObjectSizeMemberShapeType.class.getName());
38+
39+
private static final Map<ShapeId, Set<ShapeId>> SERVICE_TO_SHAPE_MAP = MapUtils.of(
40+
ShapeId.from("com.amazonaws.s3#AmazonS3"), SetUtils.of(
41+
ShapeId.from("com.amazonaws.s3#Size")
42+
)
43+
);
44+
45+
@Override
46+
public byte getOrder() {
47+
// This integration should happen before other integrations that rely on the presence of this trait
48+
return -60;
49+
}
50+
51+
@Override
52+
public Model preprocessModel(PluginContext context, TypeScriptSettings settings) {
53+
Model model = context.getModel();
54+
ShapeId serviceId = settings.getService();
55+
if (!SERVICE_TO_SHAPE_MAP.containsKey(serviceId)) {
56+
return model;
57+
}
58+
59+
Set<ShapeId> shapeIds = SERVICE_TO_SHAPE_MAP.get(serviceId);
60+
61+
Model.Builder builder = model.toBuilder();
62+
for (ShapeId shapeId : shapeIds) {
63+
OptionalUtils.ifPresentOrElse(
64+
model.getShape(shapeId),
65+
(shape) -> {
66+
if (shape.isLongShape()) {
67+
LOGGER.warning("shape is already modeled as an LONG does not require backfill");
68+
return;
69+
}
70+
71+
builder.addShape(LongShape.builder()
72+
.id(shape.getId())
73+
.addTraits(shape.getAllTraits().values())
74+
.build());
75+
},
76+
() -> LOGGER.warning("shape " + shapeId + " not found in " + serviceId + " model")
77+
);
78+
}
79+
80+
return builder.build();
81+
}
82+
}

codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ software.amazon.smithy.aws.typescript.codegen.AddSqsDependency
1010
software.amazon.smithy.aws.typescript.codegen.AddBodyChecksumGeneratorDependency
1111
software.amazon.smithy.aws.typescript.codegen.AddS3Config
1212
software.amazon.smithy.aws.typescript.codegen.AddS3ControlDependency
13+
software.amazon.smithy.aws.typescript.codegen.AddS3ObjectSizeMemberShapeType
1314
software.amazon.smithy.aws.typescript.codegen.AddEventStreamHandlingDependency
1415
software.amazon.smithy.aws.typescript.codegen.AddHttp2Dependency
1516
software.amazon.smithy.aws.typescript.codegen.AddTranscribeStreamingDependency

0 commit comments

Comments
 (0)