Repository: smithy-lang/smithy
Pull request #2061 (2023-12-05 16:45:00)

Add httpChecksumRequired to aws protocols



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/docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst b/docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst
index 5ebe9a71a..9ed49343d 100644
--- a/docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst
+++ b/docs/source-2.0/aws/protocols/aws-restjson1-protocol.rst
@@ -174,6 +174,8 @@ that affect serialization:
       - Binds a top-level input structure member to a query string parameter.
     * - :ref:`httpQueryParams <httpQueryParams-trait>`
       - Binds a map of key-value pairs to query string parameters.
+    * - :ref:`httpChecksumRequired <httpChecksumRequired-trait>`
+      - Indicates that requests MUST send a checksum.
     * - :ref:`jsonName <jsonName-trait>`
       - By default, the JSON property names used in serialized structures are
         the same as a structure member name. The ``jsonName`` trait changes
diff --git a/docs/source-2.0/aws/protocols/aws-restxml-protocol.rst b/docs/source-2.0/aws/protocols/aws-restxml-protocol.rst
index e266fc653..2ce6eaecf 100644
--- a/docs/source-2.0/aws/protocols/aws-restxml-protocol.rst
+++ b/docs/source-2.0/aws/protocols/aws-restxml-protocol.rst
@@ -163,6 +163,8 @@ that affect serialization:
       - Binds a top-level input structure member to a query string parameter.
     * - :ref:`httpQueryParams <httpQueryParams-trait>`
       - Binds a map of key-value pairs to query string parameters.
+    * - :ref:`httpChecksumRequired <httpChecksumRequired-trait>`
+      - Indicates that requests MUST send a checksum.
     * - :ref:`xmlAttribute <xmlAttribute-trait>`
       - Serializes an object property as an XML attribute rather than a nested
         XML element.
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 5b9746e23..35d413ff0 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
@@ -148,6 +148,7 @@ structure httpChecksum {
         httpQuery
         httpQueryParams
         httpResponseCode
+        httpChecksumRequired
         jsonName
     ]
 )
@@ -172,6 +173,7 @@ structure restJson1 with [HttpConfiguration] {}
         httpQuery
         httpQueryParams
         httpResponseCode
+        httpChecksumRequired
         xmlAttribute
         xmlFlattened
         xmlName
diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java
index 5dbac8017..486c51fcd 100644
--- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java
+++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java
@@ -337,6 +337,23 @@ public final class ExamplesTrait extends AbstractTrait implements ToSmithyBuilde
                 return this;
             }
         }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(shapeId, content);
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if (other == this) {
+                return true;
+            }
+            if (other == null || other.getClass() != this.getClass()) {
+                return false;
+            }
+            ErrorExample otherExample = (ErrorExample) other;
+            return Objects.equals(shapeId, otherExample.shapeId) && Objects.equals(content, otherExample.content);
+        }
     }
 
     public static final class Provider implements TraitService {


Test patch:
diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExamplesTraitTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExamplesTraitTest.java
index 37c3dab47..761e0fd99 100644
--- a/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExamplesTraitTest.java
+++ b/smithy-model/src/test/java/software/amazon/smithy/model/traits/ExamplesTraitTest.java
@@ -17,6 +17,7 @@ package software.amazon.smithy.model.traits;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.instanceOf;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -27,6 +28,8 @@ import software.amazon.smithy.model.node.ArrayNode;
 import software.amazon.smithy.model.node.Node;
 import software.amazon.smithy.model.node.ObjectNode;
 import software.amazon.smithy.model.shapes.ShapeId;
+import software.amazon.smithy.model.traits.ExamplesTrait.ErrorExample;
+import software.amazon.smithy.model.traits.ExamplesTrait.Example;
 
 public class ExamplesTraitTest {
     @Test
@@ -81,4 +84,24 @@ public class ExamplesTraitTest {
         assertFalse(serialized.get(1).get().asObjectNode().get().getMember("allowConstraintErrors").isPresent());
         assertTrue(serialized.get(2).get().asObjectNode().get().getMember("allowConstraintErrors").isPresent());
     }
+
+    @Test
+    public void exampleEqualsWorks() {
+        ObjectNode input = Node.objectNode().withMember("a", Node.from("b"));
+        ObjectNode output = Node.objectNode().withMember("c", Node.from("d"));
+        ErrorExample errorExample1 = ErrorExample.builder().shapeId(ShapeId.from("smithy.example#FooError")).content(Node.objectNode()
+                .withMember("e", Node.from("f"))).build();
+        ErrorExample errorExample2 = ErrorExample.builder().shapeId(ShapeId.from("smithy.example#FooError")).content(Node.objectNode()
+                .withMember("e", Node.from("f"))).build();
+        ErrorExample errorExample3 = ErrorExample.builder().shapeId(ShapeId.from("smithy.example#FooError")).content(Node.objectNode()
+                .withMember("g", Node.from("h"))).build();
+        Example example1 = Example.builder().title("foo").documentation("docs").input(input).output(output).error(errorExample1).build();
+        Example example2 = Example.builder().title("foo").documentation("docs").input(input).output(output).error(errorExample2).build();
+        Example example3 = Example.builder().title("foo").documentation("docs").input(input).output(output).error(errorExample3).build();
+        assertThat(errorExample1, equalTo(errorExample2));
+        assertThat(errorExample1, not(equalTo(errorExample3)));
+        assertThat(example1, equalTo(example2));
+        assertThat(example1, not(equalTo(example3)));
+    }
+
 }