Skip to content

Commit 6c0e937

Browse files
author
Steven Yuan
committed
add runtime checks
1 parent 6c2cf2a commit 6c0e937

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import software.amazon.smithy.diff.ModelDiff;
3333
import software.amazon.smithy.go.codegen.AddOperationShapes;
3434
import software.amazon.smithy.go.codegen.GoSettings;
35+
import software.amazon.smithy.go.codegen.Synthetic;
3536
import software.amazon.smithy.go.codegen.integration.GoIntegration;
3637
import software.amazon.smithy.model.Model;
3738
import software.amazon.smithy.model.loader.ModelAssembler;
@@ -154,7 +155,7 @@ public Model preprocessModel(Model model, GoSettings settings) {
154155
}
155156
throw new CodegenException(sb.toString());
156157
}
157-
validateNullabilityExceptions(nullabilityExceptions, model);
158+
validateNullabilityExceptions(nullabilityExceptions, model, service);
158159
return model;
159160
}
160161

@@ -318,7 +319,7 @@ private static Model handleApiGateWayExportsNullabilityExceptions(
318319
return ModelTransformer.create().replaceShapes(model, shapesToReplace);
319320
}
320321

321-
private static void validateNullabilityExceptions(Set<ShapeId> nullabilityExceptions, Model model) {
322+
private static void validateNullabilityExceptions(Set<ShapeId> nullabilityExceptions, Model model, ShapeId service) {
322323
Map<ShapeId, Shape> nullabilityExceptionMap = new HashMap<>();
323324
for (ShapeId shapeId : nullabilityExceptions) {
324325
if (model.getShape(shapeId).isPresent()) {
@@ -327,6 +328,31 @@ private static void validateNullabilityExceptions(Set<ShapeId> nullabilityExcept
327328
LOGGER.warning("Shape `" + shapeId + "` nullability exception is not present in the model");
328329
}
329330
}
331+
332+
for (BooleanShape shape : model.getBooleanShapesWithTrait(DefaultTrait.class)) {
333+
ShapeId shapeId = shape.toShapeId();
334+
String namespace = shapeId.getNamespace();
335+
if (!namespace.equals(service.getNamespace()) && !namespace.equals(Synthetic.ID.getNamespace())) {
336+
continue;
337+
}
338+
if (!nullabilityExceptions.contains(shapeId)) {
339+
throw new CodegenException("Shape `" + shapeId + "` should be in nullability exceptions");
340+
}
341+
}
342+
343+
for (NumberShape shape : model.toSet(NumberShape.class).stream()
344+
.filter(s -> s.hasTrait(DefaultTrait.class))
345+
.collect(Collectors.toList())) {
346+
ShapeId shapeId = shape.toShapeId();
347+
String namespace = shapeId.getNamespace();
348+
if (!namespace.equals(service.getNamespace()) && !namespace.equals(Synthetic.ID.getNamespace())) {
349+
continue;
350+
}
351+
if (!nullabilityExceptions.contains(shapeId)) {
352+
throw new CodegenException("Shape `" + shapeId + "` should be in nullability exceptions");
353+
}
354+
}
355+
330356
// Existing “defaulted” root boolean or number shapes MUST be backfilled with a
331357
// default trait.
332358
for (Map.Entry<ShapeId, Shape> entry : nullabilityExceptionMap.entrySet()) {

0 commit comments

Comments
 (0)