diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java index 047b38d6815..f2cc75d07e3 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/HttpChecksumTraitValidator.java @@ -74,7 +74,8 @@ private List validateOperation(Model model, OperationShape oper trait.isRequestChecksumRequired() || trait.getRequestAlgorithmMember().isPresent(); // Response checksum behavior is defined when either the `requestValidationModeMember` - // property or `responseAlgorithms` property are modeled. + // property or `responseAlgorithms` property are modeled. Actually both are needed, but this check helps do + // deeper validation later. boolean isResponseChecksumConfiguration = !trait.getResponseAlgorithms().isEmpty() || trait.getRequestValidationModeMember().isPresent(); @@ -236,6 +237,13 @@ private List validateResponseChecksumConfiguration( validateValidationModeMember(model, trait, operation, input).map(events::add); } + // Validate responseAlgorithms is not empty. + if (trait.getResponseAlgorithms().isEmpty()) { + events.add(error(operation, trait, "The `httpChecksum` trait must model the" + + " `responseAlgorithms` property to support response checksum behavior.")); + return events; + } + // Check for header binding conflicts with each error shape. if (!operation.getErrors().isEmpty()) { for (ShapeId id : operation.getErrors()) { diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/http-checksum-trait.errors b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/http-checksum-trait.errors index fb7502a6eb9..750e98437f0 100644 --- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/http-checksum-trait.errors +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/http-checksum-trait.errors @@ -1,5 +1,7 @@ [SUPPRESSED] smithy.example#NoBehavior: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait [SUPPRESSED] smithy.example#NoModeForResponse: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait [SUPPRESSED] smithy.example#NoOutputForResponse: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait +[SUPPRESSED] smithy.example#NoResponseAlgorithms: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait [ERROR] smithy.example#NoBehavior: The `httpChecksum` trait must define at least one of the `request` or `response` checksum behaviors. | HttpChecksumTrait [ERROR] smithy.example#NoModeForResponse: The `httpChecksum` trait must model the `requestValidationModeMember` property to support response checksum behavior. | HttpChecksumTrait +[ERROR] smithy.example#NoResponseAlgorithms: The `httpChecksum` trait must model the `responseAlgorithms` property to support response checksum behavior. | HttpChecksumTrait diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/http-checksum-trait.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/http-checksum-trait.smithy index 800cb375ace..24ce4cf32c6 100644 --- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/http-checksum-trait.smithy +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/http-checksum-trait.smithy @@ -37,6 +37,24 @@ structure NoModeForResponseInput {} @output structure NoModeForResponseOutput {} +@httpChecksum( + requestValidationModeMember: "validationMode" +) +@suppress(["UnstableTrait"]) +operation NoResponseAlgorithms { + input: NoResponseAlgorithmsInput, + output: NoResponseAlgorithmsOutput, +} + +@input +structure NoResponseAlgorithmsInput { + validationMode: ValidationMode +} + +@output +structure NoResponseAlgorithmsOutput {} + + @httpChecksum( requestAlgorithmMember: "requestAlgorithm", requestValidationModeMember: "validationMode",