Skip to content

Commit 27360c1

Browse files
Steven Yuansbiscigl
authored andcommitted
fix APIGW exports nullability exceptions
1 parent 30383d5 commit 27360c1

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "1e8147ce-9c59-435a-aab1-1ac917d0dfb2",
3+
"type": "bugfix",
4+
"description": "Fix APIGW exports nullability exceptions strictness.",
5+
"modules": [
6+
"codegen"
7+
]
8+
}

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegration.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.HashSet;
2020
import java.util.List;
21+
import java.util.Optional;
2122
import java.util.Set;
2223
import java.util.logging.Logger;
2324
import java.util.stream.Collectors;
@@ -147,7 +148,12 @@ private void patchDefaultsForRootLevelSnapshottedShapes(
147148
Set<NumberShape> numberShapes,
148149
Set<MemberShape> memberShapes) {
149150
for (ShapeId shapeId : nullabilityExceptions) {
150-
Shape shape = model.expectShape(shapeId);
151+
Optional<Shape> shapeOptional = model.getShape(shapeId);
152+
if (!shapeOptional.isPresent()) {
153+
LOGGER.severe("ShapeId `" + shapeId.toString() + "` is not present in the model");
154+
continue;
155+
}
156+
Shape shape = shapeOptional.get();
151157
if (shape.hasTrait(DefaultTrait.class)) {
152158
continue;
153159
}
@@ -176,7 +182,12 @@ private void patchDefaultsForMemberLevelSnapshottedShapes(
176182
Set<NumberShape> numberShapes,
177183
Set<MemberShape> memberShapes) {
178184
for (ShapeId shapeId : nullabilityExceptions) {
179-
Shape shape = model.expectShape(shapeId);
185+
Optional<Shape> shapeOptional = model.getShape(shapeId);
186+
if (!shapeOptional.isPresent()) {
187+
LOGGER.severe("ShapeId `" + shapeId.toString() + "` is not present in the model");
188+
continue;
189+
}
190+
Shape shape = shapeOptional.get();
180191
if (shape.hasTrait(DefaultTrait.class)) {
181192
continue;
182193
}

codegen/smithy-aws-go-codegen/src/main/resources/software/amazon/smithy/aws/go/codegen/customization/APIGW_exports_nullability_exceptions.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,8 @@
10701070
"com.amazonaws.mediaconvert#Vp9Settings$MaxBitrate",
10711071
"com.amazonaws.mediaconvert#Vp9Settings$ParDenominator",
10721072
"com.amazonaws.mediaconvert#Vp9Settings$ParNumerator",
1073+
"com.amazonaws.mediaconvert#WarningGroup$Code",
1074+
"com.amazonaws.mediaconvert#WarningGroup$Count",
10731075
"com.amazonaws.mediaconvert#WavSettings$BitDepth",
10741076
"com.amazonaws.mediaconvert#WavSettings$Channels",
10751077
"com.amazonaws.mediaconvert#WavSettings$SampleRate",

codegen/smithy-aws-go-codegen/src/test/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegrationTest.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import java.nio.file.Path;
2424
import java.util.ArrayList;
2525
import java.util.List;
26+
import java.util.Optional;
2627
import java.util.Set;
28+
import java.util.logging.Logger;
2729
import java.util.stream.Collectors;
2830
import java.util.stream.Stream;
2931
import org.junit.jupiter.api.Test;
@@ -50,6 +52,8 @@
5052
import software.amazon.smithy.utils.MapUtils;
5153

5254
public class ApiGatewayExportsNullabilityExceptionIntegrationTest {
55+
private static final Logger LOGGER = Logger
56+
.getLogger(ApiGatewayExportsNullabilityExceptionIntegrationTest.class.getName());
5357
private static final String PATH_PREFIX = "../sdk-codegen/aws-models/";
5458
private static final String NULLABILITY_EXCEPTIONS_FILE = "APIGW_exports_nullability_exceptions.json";
5559

@@ -59,7 +63,12 @@ public class ApiGatewayExportsNullabilityExceptionIntegrationTest {
5963
@ParameterizedTest
6064
@MethodSource("apigwNullabilityExceptionServices")
6165
public void test_APIGW_exports_nullability_exception_services(String modelFile) {
62-
loadPreprocessedModel(modelFile);
66+
try {
67+
loadPreprocessedModel(modelFile);
68+
} catch (Exception e) {
69+
LOGGER.severe(e.getMessage());
70+
throw e;
71+
}
6372
}
6473

6574
private static Stream<Arguments> apigwNullabilityExceptionServices() {
@@ -144,6 +153,7 @@ public void test_unaffected_MediaLive_APIGW_default_strings() {
144153
bodyShape.expectTrait(DefaultTrait.class).toNode().asStringNode().get().getValue());
145154
}
146155

156+
/*
147157
@Test
148158
public void test_missing_snapshotted_root_level_shape() {
149159
ApiGatewayExportsNullabilityExceptionIntegration integration = new ApiGatewayExportsNullabilityExceptionIntegration();
@@ -162,7 +172,9 @@ public void test_missing_snapshotted_root_level_shape() {
162172
ShapeId.from("com.amazonaws.pinpointsmsvoice#RenamedBoolean")));
163173
assertThrows(ExpectationNotMetException.class, () -> integration.preprocessModel(renamedShapesModel, settings));
164174
}
175+
*/
165176

177+
/*
166178
@Test
167179
public void test_missing_snapshotted_member_level_shape() {
168180
ApiGatewayExportsNullabilityExceptionIntegration integration = new ApiGatewayExportsNullabilityExceptionIntegration();
@@ -180,6 +192,7 @@ public void test_missing_snapshotted_member_level_shape() {
180192
model.expectShape(ShapeId.from("com.amazonaws.pinpointsmsvoice#EventDestination$Enabled"))));
181193
assertThrows(ExpectationNotMetException.class, () -> integration.preprocessModel(removedShapesModel, settings));
182194
}
195+
*/
183196

184197
@Test
185198
public void test_identify_nonsnapshotted_member_level_shape() {
@@ -242,11 +255,16 @@ private Model stripDefaultsFromModel(Model model, ShapeId service) {
242255
List<Shape> shapesToReplace = new ArrayList<>();
243256
// Strip root shapes
244257
for (ShapeId shapeId : shapeIdsToReplace) {
245-
Shape shape = model.expectShape(shapeId);
246-
if (shape.hasTrait(DefaultTrait.class)) {
247-
shapesToReplace.add(Shape.shapeToBuilder(shape)
248-
.removeTrait(DefaultTrait.ID)
249-
.build());
258+
// TODO: clean this up later
259+
Optional<Shape> shape = model.getShape(shapeId);
260+
if (shape.isPresent()) {
261+
if (shape.get().hasTrait(DefaultTrait.class)) {
262+
shapesToReplace.add(Shape.shapeToBuilder(shape.get())
263+
.removeTrait(DefaultTrait.ID)
264+
.build());
265+
}
266+
} else {
267+
LOGGER.severe("ShapeId `" + shapeId.toString() + "` is not present in the model");
250268
}
251269
}
252270
// Strip member shapes that target affected root shapes
@@ -266,6 +284,9 @@ private Model stripDefaultsFromModel(Model model, ShapeId service) {
266284
Model strippedModel = ModelTransformer.create().replaceShapes(model, shapesToReplace);
267285
// Assert root shape defaults are removed
268286
for (ShapeId shapeId : shapeIdsToReplace) {
287+
if (!strippedModel.getShape(shapeId).isPresent()) {
288+
continue;
289+
}
269290
assertFalse(strippedModel.expectShape(shapeId).hasTrait(DefaultTrait.class));
270291
}
271292
// Assert member shape defaults are removed

0 commit comments

Comments
 (0)