diff --git a/.changelog/1e8147ce9c59435aaab11ac917d0dfb2.json b/.changelog/1e8147ce9c59435aaab11ac917d0dfb2.json new file mode 100644 index 00000000000..b9aa38571dc --- /dev/null +++ b/.changelog/1e8147ce9c59435aaab11ac917d0dfb2.json @@ -0,0 +1,8 @@ +{ + "id": "1e8147ce-9c59-435a-aab1-1ac917d0dfb2", + "type": "bugfix", + "description": "Fix APIGW exports nullability exceptions strictness.", + "modules": [ + "codegen" + ] +} \ No newline at end of file diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegration.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegration.java index 3e408a35830..a5b8c8b43ad 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegration.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegration.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -147,7 +148,12 @@ private void patchDefaultsForRootLevelSnapshottedShapes( Set numberShapes, Set memberShapes) { for (ShapeId shapeId : nullabilityExceptions) { - Shape shape = model.expectShape(shapeId); + Optional shapeOptional = model.getShape(shapeId); + if (!shapeOptional.isPresent()) { + LOGGER.severe("ShapeId `" + shapeId.toString() + "` is not present in the model"); + continue; + } + Shape shape = shapeOptional.get(); if (shape.hasTrait(DefaultTrait.class)) { continue; } @@ -176,7 +182,12 @@ private void patchDefaultsForMemberLevelSnapshottedShapes( Set numberShapes, Set memberShapes) { for (ShapeId shapeId : nullabilityExceptions) { - Shape shape = model.expectShape(shapeId); + Optional shapeOptional = model.getShape(shapeId); + if (!shapeOptional.isPresent()) { + LOGGER.severe("ShapeId `" + shapeId.toString() + "` is not present in the model"); + continue; + } + Shape shape = shapeOptional.get(); if (shape.hasTrait(DefaultTrait.class)) { continue; } diff --git a/codegen/smithy-aws-go-codegen/src/main/resources/software/amazon/smithy/aws/go/codegen/customization/APIGW_exports_nullability_exceptions.json b/codegen/smithy-aws-go-codegen/src/main/resources/software/amazon/smithy/aws/go/codegen/customization/APIGW_exports_nullability_exceptions.json index fcb1dc23066..42494107338 100644 --- a/codegen/smithy-aws-go-codegen/src/main/resources/software/amazon/smithy/aws/go/codegen/customization/APIGW_exports_nullability_exceptions.json +++ b/codegen/smithy-aws-go-codegen/src/main/resources/software/amazon/smithy/aws/go/codegen/customization/APIGW_exports_nullability_exceptions.json @@ -1070,6 +1070,8 @@ "com.amazonaws.mediaconvert#Vp9Settings$MaxBitrate", "com.amazonaws.mediaconvert#Vp9Settings$ParDenominator", "com.amazonaws.mediaconvert#Vp9Settings$ParNumerator", + "com.amazonaws.mediaconvert#WarningGroup$Code", + "com.amazonaws.mediaconvert#WarningGroup$Count", "com.amazonaws.mediaconvert#WavSettings$BitDepth", "com.amazonaws.mediaconvert#WavSettings$Channels", "com.amazonaws.mediaconvert#WavSettings$SampleRate", diff --git a/codegen/smithy-aws-go-codegen/src/test/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegrationTest.java b/codegen/smithy-aws-go-codegen/src/test/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegrationTest.java index c77b3fc2630..83dd139cf2d 100644 --- a/codegen/smithy-aws-go-codegen/src/test/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegrationTest.java +++ b/codegen/smithy-aws-go-codegen/src/test/java/software/amazon/smithy/aws/go/codegen/customization/ApiGatewayExportsNullabilityExceptionIntegrationTest.java @@ -23,7 +23,9 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.Set; +import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -50,6 +52,8 @@ import software.amazon.smithy.utils.MapUtils; public class ApiGatewayExportsNullabilityExceptionIntegrationTest { + private static final Logger LOGGER = Logger + .getLogger(ApiGatewayExportsNullabilityExceptionIntegrationTest.class.getName()); private static final String PATH_PREFIX = "../sdk-codegen/aws-models/"; private static final String NULLABILITY_EXCEPTIONS_FILE = "APIGW_exports_nullability_exceptions.json"; @@ -59,7 +63,12 @@ public class ApiGatewayExportsNullabilityExceptionIntegrationTest { @ParameterizedTest @MethodSource("apigwNullabilityExceptionServices") public void test_APIGW_exports_nullability_exception_services(String modelFile) { - loadPreprocessedModel(modelFile); + try { + loadPreprocessedModel(modelFile); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + throw e; + } } private static Stream apigwNullabilityExceptionServices() { @@ -144,6 +153,7 @@ public void test_unaffected_MediaLive_APIGW_default_strings() { bodyShape.expectTrait(DefaultTrait.class).toNode().asStringNode().get().getValue()); } + /* @Test public void test_missing_snapshotted_root_level_shape() { ApiGatewayExportsNullabilityExceptionIntegration integration = new ApiGatewayExportsNullabilityExceptionIntegration(); @@ -162,7 +172,9 @@ public void test_missing_snapshotted_root_level_shape() { ShapeId.from("com.amazonaws.pinpointsmsvoice#RenamedBoolean"))); assertThrows(ExpectationNotMetException.class, () -> integration.preprocessModel(renamedShapesModel, settings)); } + */ + /* @Test public void test_missing_snapshotted_member_level_shape() { ApiGatewayExportsNullabilityExceptionIntegration integration = new ApiGatewayExportsNullabilityExceptionIntegration(); @@ -180,6 +192,7 @@ public void test_missing_snapshotted_member_level_shape() { model.expectShape(ShapeId.from("com.amazonaws.pinpointsmsvoice#EventDestination$Enabled")))); assertThrows(ExpectationNotMetException.class, () -> integration.preprocessModel(removedShapesModel, settings)); } + */ @Test public void test_identify_nonsnapshotted_member_level_shape() { @@ -242,11 +255,16 @@ private Model stripDefaultsFromModel(Model model, ShapeId service) { List shapesToReplace = new ArrayList<>(); // Strip root shapes for (ShapeId shapeId : shapeIdsToReplace) { - Shape shape = model.expectShape(shapeId); - if (shape.hasTrait(DefaultTrait.class)) { - shapesToReplace.add(Shape.shapeToBuilder(shape) - .removeTrait(DefaultTrait.ID) - .build()); + // TODO: clean this up later + Optional shape = model.getShape(shapeId); + if (shape.isPresent()) { + if (shape.get().hasTrait(DefaultTrait.class)) { + shapesToReplace.add(Shape.shapeToBuilder(shape.get()) + .removeTrait(DefaultTrait.ID) + .build()); + } + } else { + LOGGER.severe("ShapeId `" + shapeId.toString() + "` is not present in the model"); } } // Strip member shapes that target affected root shapes @@ -266,6 +284,9 @@ private Model stripDefaultsFromModel(Model model, ShapeId service) { Model strippedModel = ModelTransformer.create().replaceShapes(model, shapesToReplace); // Assert root shape defaults are removed for (ShapeId shapeId : shapeIdsToReplace) { + if (!strippedModel.getShape(shapeId).isPresent()) { + continue; + } assertFalse(strippedModel.expectShape(shapeId).hasTrait(DefaultTrait.class)); } // Assert member shape defaults are removed