diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java index 890c9fda867..87e91abf114 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java @@ -83,23 +83,27 @@ public List evaluate(Differences differences) { } // Validate Operation effective auth schemes for (ServiceShape newServiceShape : newOperationServiceBindings) { - ServiceShape oldServiceShape = oldModel.expectShape(newServiceShape.getId(), ServiceShape.class); - OperationShape oldOperationShape = change.getOldShape(); - List oldAuthSchemes = oldServiceIndex - .getEffectiveAuthSchemes(oldServiceShape, oldOperationShape) - .keySet() - .stream() - .collect(Collectors.toList()); - List newAuthSchemes = newServiceIndex - .getEffectiveAuthSchemes(newServiceShape, newOperationShape) - .keySet() - .stream() - .collect(Collectors.toList()); - validateMigration( - newOperationShape, - oldAuthSchemes, - newAuthSchemes, - events); + oldModel.getShape(newServiceShape.getId()) + .filter(Shape::isServiceShape) + .map(s -> (ServiceShape) s) + .ifPresent(oldServiceShape -> { + OperationShape oldOperationShape = change.getOldShape(); + List oldAuthSchemes = oldServiceIndex + .getEffectiveAuthSchemes(oldServiceShape, oldOperationShape) + .keySet() + .stream() + .collect(Collectors.toList()); + List newAuthSchemes = newServiceIndex + .getEffectiveAuthSchemes(newServiceShape, newOperationShape) + .keySet() + .stream() + .collect(Collectors.toList()); + validateMigration( + newOperationShape, + oldAuthSchemes, + newAuthSchemes, + events); + }); } } diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.a.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.a.smithy new file mode 100644 index 00000000000..e75d0177d05 --- /dev/null +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.a.smithy @@ -0,0 +1,21 @@ +$version: "2.0" + +metadata suppressions = [ + { + id: "ModifiedTrait.Update.smithy.api#auth" + namespace: "ns.foo" + } +] + +namespace ns.foo + +@auth([]) +@httpBearerAuth +service Service { + operations: [ + Operation + ] +} + +@auth([]) +operation Operation {} diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.b.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.b.smithy new file mode 100644 index 00000000000..44870b7e793 --- /dev/null +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.b.smithy @@ -0,0 +1,30 @@ +$version: "2.0" + +metadata suppressions = [ + { + id: "ModifiedTrait.Update.smithy.api#auth" + namespace: "ns.foo" + } +] + +namespace ns.foo + +@auth([httpBearerAuth]) +@httpBearerAuth +service Service { + operations: [ + Operation + ] +} + +@auth([httpBearerAuth]) +@httpBearerAuth +service NewService { + operations: [ + Operation + ] +} + + +@auth([httpBearerAuth]) +operation Operation {} diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events new file mode 100644 index 00000000000..7ebdd3d2dc3 --- /dev/null +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events @@ -0,0 +1 @@ +[NOTE] ns.foo#NewService: Added service `ns.foo#NewService` | AddedShape