Repository: smithy-lang/smithy
Pull request #2398 (2024-09-17 19:22:23)

Add breakingChanges for httpChecksum trait
#### Background
The `aws.protocols#httpChecksum` trait was missing any rules for detecting backwards incompatible changes to the applied trait. This PR adds `breakingChanges` to the trait definition.

#### Testing
Added tests to assert the events for diff.

#### Links

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Patch:
diff --git a/smithy-aws-traits/src/main/resources/META-INF/smithy/aws.protocols.smithy b/smithy-aws-traits/src/main/resources/META-INF/smithy/aws.protocols.smithy
index ceb88995c..d4a7be98f 100644
--- a/smithy-aws-traits/src/main/resources/META-INF/smithy/aws.protocols.smithy
+++ b/smithy-aws-traits/src/main/resources/META-INF/smithy/aws.protocols.smithy
@@ -123,7 +123,45 @@ structure ec2Query {}
 string ec2QueryName
 
 /// Indicates that an operation supports checksum validation.
-@trait(selector: "operation")
+@trait(
+    selector: "operation",
+    breakingChanges: [
+        {
+            change: "remove",
+            severity: "DANGER",
+            message: """
+                Removing the trait removes the ability for clients to do request or response checksums. The service \
+                MUST continue to support old clients by supporting the `httpChecksum` trait."""
+        },
+        {
+            change: "remove",
+            path: "/requestAlgorithmMember",
+            severity: "DANGER",
+            message: """
+                `requestAlgorithmMember` was removed, so newly generated clients will no longer be able to pick the \
+                request checksum algorithms The service MUST continue to support old clients by supporting \
+                `requestAlgorithmMember`."""
+        },
+        {
+            change: "remove",
+            path: "/requestValidationModeMember",
+            severity: "DANGER",
+            message: """
+                `requestValidationModeMember` was removed, so newly generated clients will no longer validate response \
+                checksums. The service MUST continue to support old clients by supporting \
+                `requestValidationModeMember`."""
+        },
+        {
+            change: "remove",
+            path: "/responseAlgorithms/member",
+            severity: "DANGER",
+            message: """
+                Members of `responseAlgorithms` were removed, so newly generated clients will no longer validate \
+                response checksums for the removed algorithms. The service MUST continue to support old clients by \
+                supporting removed compression algorithms."""
+        }
+    ]
+)
 @unstable
 structure httpChecksum {
     /// Defines a top-level operation input member that is used to configure


Test patch:
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.a.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.a.smithy
new file mode 100644
index 000000000..82e24a3e8
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.a.smithy
@@ -0,0 +1,41 @@
+$version: "2.0"
+
+namespace ns.foo
+
+use aws.protocols#httpChecksum
+
+service Service {
+    operations: [
+        PutSomething
+    ]
+}
+
+@httpChecksum(
+    requestChecksumRequired: true,
+    requestAlgorithmMember: "checksumAlgorithm"
+)
+operation PutSomething {
+    input: PutSomethingInput
+}
+
+structure PutSomethingInput {
+    @httpHeader("x-amz-request-algorithm")
+    checksumAlgorithm: ChecksumAlgorithm
+
+    @httpHeader("x-amz-response-validation-mode")
+    validationMode: ValidationMode
+
+    @httpPayload
+    content: Blob
+}
+
+enum ChecksumAlgorithm {
+    CRC32C
+    CRC32
+    SHA1
+    SHA256
+}
+
+enum ValidationMode {
+    ENABLED
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.b.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.b.smithy
new file mode 100644
index 000000000..b667c23d2
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.b.smithy
@@ -0,0 +1,40 @@
+$version: "2.0"
+
+namespace ns.foo
+
+use aws.protocols#httpChecksum
+
+service Service {
+    operations: [
+        PutSomething
+    ]
+}
+
+@httpChecksum(
+    requestChecksumRequired: true
+)
+operation PutSomething {
+    input: PutSomethingInput
+}
+
+structure PutSomethingInput {
+    @httpHeader("x-amz-request-algorithm")
+    checksumAlgorithm: ChecksumAlgorithm
+
+    @httpHeader("x-amz-response-validation-mode")
+    validationMode: ValidationMode
+
+    @httpPayload
+    content: Blob
+}
+
+enum ChecksumAlgorithm {
+    CRC32C
+    CRC32
+    SHA1
+    SHA256
+}
+
+enum ValidationMode {
+    ENABLED
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.events b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.events
new file mode 100644
index 000000000..1f969c445
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-request.events
@@ -0,0 +1,1 @@
+[DANGER] ns.foo#PutSomething: Removed trait contents from `aws.protocols#httpChecksum` at path `/requestAlgorithmMember`. Removed value: `checksumAlgorithm`; `requestAlgorithmMember` was removed, so newly generated clients will no longer be able to pick the request checksum algorithms The service MUST continue to support old clients by supporting `requestAlgorithmMember`. | TraitBreakingChange.Remove
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.a.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.a.smithy
new file mode 100644
index 000000000..eefd68dbf
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.a.smithy
@@ -0,0 +1,41 @@
+$version: "2.0"
+
+namespace ns.foo
+
+use aws.protocols#httpChecksum
+
+service Service {
+    operations: [
+        PutSomething
+    ]
+}
+
+@httpChecksum(
+    requestValidationModeMember: "validationMode",
+    responseAlgorithms: ["CRC32C", "CRC32", "SHA1", "SHA256"]
+)
+operation PutSomething {
+    input: PutSomethingInput
+}
+
+structure PutSomethingInput {
+    @httpHeader("x-amz-request-algorithm")
+    checksumAlgorithm: ChecksumAlgorithm
+
+    @httpHeader("x-amz-response-validation-mode")
+    validationMode: ValidationMode
+
+    @httpPayload
+    content: Blob
+}
+
+enum ChecksumAlgorithm {
+    CRC32C
+    CRC32
+    SHA1
+    SHA256
+}
+
+enum ValidationMode {
+    ENABLED
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.b.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.b.smithy
new file mode 100644
index 000000000..f23a3f150
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.b.smithy
@@ -0,0 +1,41 @@
+$version: "2.0"
+
+namespace ns.foo
+
+use aws.protocols#httpChecksum
+
+service Service {
+    operations: [
+        PutSomething
+    ]
+}
+
+@httpChecksum(
+    requestValidationModeMember: "validationMode",
+    responseAlgorithms: ["CRC32C", "CRC32", "SHA1"]
+)
+operation PutSomething {
+    input: PutSomethingInput
+}
+
+structure PutSomethingInput {
+    @httpHeader("x-amz-request-algorithm")
+    checksumAlgorithm: ChecksumAlgorithm
+
+    @httpHeader("x-amz-response-validation-mode")
+    validationMode: ValidationMode
+
+    @httpPayload
+    content: Blob
+}
+
+enum ChecksumAlgorithm {
+    CRC32C
+    CRC32
+    SHA1
+    SHA256
+}
+
+enum ValidationMode {
+    ENABLED
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.events b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.events
new file mode 100644
index 000000000..8b58aad88
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response-algorithm.events
@@ -0,0 +1,1 @@
+[DANGER] ns.foo#PutSomething: Removed trait contents from `aws.protocols#httpChecksum` at path `/responseAlgorithms/3`. Removed value: `SHA256`; Members of `responseAlgorithms` were removed, so newly generated clients will no longer validate response checksums for the removed algorithms. The service MUST continue to support old clients by supporting removed compression algorithms. | TraitBreakingChange.Remove
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.a.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.a.smithy
new file mode 100644
index 000000000..04e1ef80e
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.a.smithy
@@ -0,0 +1,43 @@
+$version: "2.0"
+
+namespace ns.foo
+
+use aws.protocols#httpChecksum
+
+service Service {
+    operations: [
+        PutSomething
+    ]
+}
+
+@httpChecksum(
+    requestChecksumRequired: true,
+    requestAlgorithmMember: "checksumAlgorithm",
+    requestValidationModeMember: "validationMode",
+    responseAlgorithms: ["CRC32C", "CRC32", "SHA1", "SHA256"]
+)
+operation PutSomething {
+    input: PutSomethingInput
+}
+
+structure PutSomethingInput {
+    @httpHeader("x-amz-request-algorithm")
+    checksumAlgorithm: ChecksumAlgorithm
+
+    @httpHeader("x-amz-response-validation-mode")
+    validationMode: ValidationMode
+
+    @httpPayload
+    content: Blob
+}
+
+enum ChecksumAlgorithm {
+    CRC32C
+    CRC32
+    SHA1
+    SHA256
+}
+
+enum ValidationMode {
+    ENABLED
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.b.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.b.smithy
new file mode 100644
index 000000000..82e24a3e8
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.b.smithy
@@ -0,0 +1,41 @@
+$version: "2.0"
+
+namespace ns.foo
+
+use aws.protocols#httpChecksum
+
+service Service {
+    operations: [
+        PutSomething
+    ]
+}
+
+@httpChecksum(
+    requestChecksumRequired: true,
+    requestAlgorithmMember: "checksumAlgorithm"
+)
+operation PutSomething {
+    input: PutSomethingInput
+}
+
+structure PutSomethingInput {
+    @httpHeader("x-amz-request-algorithm")
+    checksumAlgorithm: ChecksumAlgorithm
+
+    @httpHeader("x-amz-response-validation-mode")
+    validationMode: ValidationMode
+
+    @httpPayload
+    content: Blob
+}
+
+enum ChecksumAlgorithm {
+    CRC32C
+    CRC32
+    SHA1
+    SHA256
+}
+
+enum ValidationMode {
+    ENABLED
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.events b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.events
new file mode 100644
index 000000000..e514aeb4f
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum-response.events
@@ -0,0 +1,9 @@
+[DANGER] ns.foo#PutSomething: Removed trait contents from `aws.protocols#httpChecksum` at path `/requestValidationModeMember`. Removed value: `validationMode`; `requestValidationModeMember` was removed, so newly generated clients will no longer validate response checksums. The service MUST continue to support old clients by supporting `requestValidationModeMember`. | TraitBreakingChange.Remove
+-----
+[DANGER] ns.foo#PutSomething: Removed trait contents from `aws.protocols#httpChecksum` at path `/responseAlgorithms/0`. Removed value: `CRC32C`; Members of `responseAlgorithms` were removed, so newly generated clients will no longer validate response checksums for the removed algorithms. The service MUST continue to support old clients by supporting removed compression algorithms. | TraitBreakingChange.Remove
+-----
+[DANGER] ns.foo#PutSomething: Removed trait contents from `aws.protocols#httpChecksum` at path `/responseAlgorithms/1`. Removed value: `CRC32`; Members of `responseAlgorithms` were removed, so newly generated clients will no longer validate response checksums for the removed algorithms. The service MUST continue to support old clients by supporting removed compression algorithms. | TraitBreakingChange.Remove
+-----
+[DANGER] ns.foo#PutSomething: Removed trait contents from `aws.protocols#httpChecksum` at path `/responseAlgorithms/2`. Removed value: `SHA1`; Members of `responseAlgorithms` were removed, so newly generated clients will no longer validate response checksums for the removed algorithms. The service MUST continue to support old clients by supporting removed compression algorithms. | TraitBreakingChange.Remove
+-----
+[DANGER] ns.foo#PutSomething: Removed trait contents from `aws.protocols#httpChecksum` at path `/responseAlgorithms/3`. Removed value: `SHA256`; Members of `responseAlgorithms` were removed, so newly generated clients will no longer validate response checksums for the removed algorithms. The service MUST continue to support old clients by supporting removed compression algorithms. | TraitBreakingChange.Remove
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.a.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.a.smithy
new file mode 100644
index 000000000..04e1ef80e
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.a.smithy
@@ -0,0 +1,43 @@
+$version: "2.0"
+
+namespace ns.foo
+
+use aws.protocols#httpChecksum
+
+service Service {
+    operations: [
+        PutSomething
+    ]
+}
+
+@httpChecksum(
+    requestChecksumRequired: true,
+    requestAlgorithmMember: "checksumAlgorithm",
+    requestValidationModeMember: "validationMode",
+    responseAlgorithms: ["CRC32C", "CRC32", "SHA1", "SHA256"]
+)
+operation PutSomething {
+    input: PutSomethingInput
+}
+
+structure PutSomethingInput {
+    @httpHeader("x-amz-request-algorithm")
+    checksumAlgorithm: ChecksumAlgorithm
+
+    @httpHeader("x-amz-response-validation-mode")
+    validationMode: ValidationMode
+
+    @httpPayload
+    content: Blob
+}
+
+enum ChecksumAlgorithm {
+    CRC32C
+    CRC32
+    SHA1
+    SHA256
+}
+
+enum ValidationMode {
+    ENABLED
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.b.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.b.smithy
new file mode 100644
index 000000000..122adcdb1
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.b.smithy
@@ -0,0 +1,35 @@
+$version: "2.0"
+
+namespace ns.foo
+
+service Service {
+    operations: [
+        PutSomething
+    ]
+}
+
+operation PutSomething {
+    input: PutSomethingInput
+}
+
+structure PutSomethingInput {
+    @httpHeader("x-amz-request-algorithm")
+    checksumAlgorithm: ChecksumAlgorithm
+
+    @httpHeader("x-amz-response-validation-mode")
+    validationMode: ValidationMode
+
+    @httpPayload
+    content: Blob
+}
+
+enum ChecksumAlgorithm {
+    CRC32C
+    CRC32
+    SHA1
+    SHA256
+}
+
+enum ValidationMode {
+    ENABLED
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.events b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.events
new file mode 100644
index 000000000..ef02675fe
--- /dev/null
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/httpChecksum.events
@@ -0,0 +1,15 @@
+[DANGER] ns.foo#PutSomething: Removed trait `aws.protocols#httpChecksum`. Previous trait value: 
+```
+{
+    "requestChecksumRequired": true,
+    "requestAlgorithmMember": "checksumAlgorithm",
+    "requestValidationModeMember": "validationMode",
+    "responseAlgorithms": [
+        "CRC32C",
+        "CRC32",
+        "SHA1",
+        "SHA256"
+    ]
+}
+```
+; Removing the trait removes the ability for clients to do request or response checksums. The service MUST continue to support old clients by supporting the `httpChecksum` trait. | TraitBreakingChange.Remove