Repository: smithy-lang/smithy
Pull request #2044 (2023-11-16 18:53:14)

Fix toShapeId call in EndpointModifierIndex
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-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndex.java b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndex.java
index 9f65c647c..ff8ccbc59 100644
--- a/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndex.java
+++ b/smithy-aws-endpoints/src/main/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndex.java
@@ -29,7 +29,7 @@ public final class EndpointModifierIndex implements KnowledgeIndex {
         for (ServiceShape serviceShape : model.getServiceShapes()) {
             Map<ShapeId, Trait> result = new TreeMap<>();
             for (Trait trait : serviceShape.getAllTraits().values()) {
-                Shape traitShape = model.getShape(trait.toShapeId()).get();
+                Shape traitShape = model.expectShape(trait.toShapeId());
                 if (traitShape.hasTrait(EndpointModifierTrait.ID)) {
                     result.put(trait.toShapeId(), trait);
                 }
@@ -49,6 +49,6 @@ public final class EndpointModifierIndex implements KnowledgeIndex {
      * @return Map of endpoint modifier trait ID to the trait
      */
     public Map<ShapeId, Trait> getEndpointModifierTraits(ToShapeId toShapeId) {
-        return endpointModifierTraits.get(toShapeId);
+        return endpointModifierTraits.get(toShapeId.toShapeId());
     }
 }
diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/SdkServiceIdValidator.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/SdkServiceIdValidator.java
index 2e7101a52..9c97c30a4 100644
--- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/SdkServiceIdValidator.java
+++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/SdkServiceIdValidator.java
@@ -114,8 +114,8 @@ public final class SdkServiceIdValidator extends AbstractValidator {
             messages.add(String.format("Must not case-insensitively end with `%s`", suffix));
         });
 
-        if (serviceId.length() < 2 || serviceId.length() > 50) {
-            messages.add("Must be between 2 and 50 characters long.");
+        if (serviceId.isEmpty() || serviceId.length() > 50) {
+            messages.add("Must be between 1 and 50 characters long.");
         }
 
         if (!messages.isEmpty()) {


Test patch:
diff --git a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndexTest.java b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndexTest.java
index 53e79c0c1..fa11edd67 100644
--- a/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndexTest.java
+++ b/smithy-aws-endpoints/src/test/java/software/amazon/smithy/rulesengine/aws/traits/EndpointModifierIndexTest.java
@@ -24,6 +24,8 @@ class EndpointModifierIndexTest {
         EndpointModifierIndex index = new EndpointModifierIndex(model);
 
         assertEquals(index.getEndpointModifierTraits(service1).size(), 1);
+        // Assert this works if you pass in the shape as well.
+        assertEquals(index.getEndpointModifierTraits(model.expectShape(service1)).size(), 1);
         assertInstanceOf(StandardRegionalEndpointsTrait.class,
                 index.getEndpointModifierTraits(service1).get(StandardRegionalEndpointsTrait.ID));
 
diff --git a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/SdkServiceIdValidatorTest.java b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/SdkServiceIdValidatorTest.java
index 0321c121c..1b6fa2227 100644
--- a/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/SdkServiceIdValidatorTest.java
+++ b/smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/SdkServiceIdValidatorTest.java
@@ -76,9 +76,9 @@ public class SdkServiceIdValidatorTest {
     @Test
     public void doesNotAllowShortIds() {
         IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () ->
-                SdkServiceIdValidator.validateServiceId("F"));
+                SdkServiceIdValidator.validateServiceId(""));
 
-        assertThat(thrown.getMessage(), containsString("2 and 50"));
+        assertThat(thrown.getMessage(), containsString("1 and 50"));
     }
 
     @Test
@@ -86,6 +86,6 @@ public class SdkServiceIdValidatorTest {
         IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () ->
                 SdkServiceIdValidator.validateServiceId("Foobarbazqux Foobarbazqux Foobarbazqux Foobarbazqux"));
 
-        assertThat(thrown.getMessage(), containsString("2 and 50"));
+        assertThat(thrown.getMessage(), containsString("1 and 50"));
     }
 }