Repository: smithy-lang/smithy
Pull request #1952 (2023-08-25 18:44:52)

Add length trait to trait index
Also adds back the `openhtml` make command, routing to the top-level index.

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/Makefile b/docs/Makefile
index e3e6c42ad..39e53b7b0 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -24,4 +24,7 @@ merge-versions:
 	cp -R "build/2.0/html" "build/html/2.0"
 	cp -R "root/" "build/html"
 
+openhtml:
+	open "build/html/index.html"
+
 .PHONY: Makefile clean
diff --git a/docs/source-1.0/spec/core/constraint-traits.rst b/docs/source-1.0/spec/core/constraint-traits.rst
index e4d9c531c..cc5a21877 100644
--- a/docs/source-1.0/spec/core/constraint-traits.rst
+++ b/docs/source-1.0/spec/core/constraint-traits.rst
@@ -315,6 +315,7 @@ Given the following model,
   ``smithy.example#MyShape``.
 
 
+.. smithy-trait:: smithy.api#length
 .. _length-trait:
 
 ----------------
diff --git a/docs/source-2.0/spec/constraint-traits.rst b/docs/source-2.0/spec/constraint-traits.rst
index 767a411c6..2440c523e 100644
--- a/docs/source-2.0/spec/constraint-traits.rst
+++ b/docs/source-2.0/spec/constraint-traits.rst
@@ -124,6 +124,7 @@ Given the following model,
   ``smithy.example#MyShape``.
 
 
+.. smithy-trait:: smithy.api#length
 .. _length-trait:
 
 ``length`` trait
diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenAndRemoveMixins.java b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenAndRemoveMixins.java
index 5aa3cfa5d..ad790d78c 100644
--- a/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenAndRemoveMixins.java
+++ b/smithy-model/src/main/java/software/amazon/smithy/model/transform/FlattenAndRemoveMixins.java
@@ -38,7 +38,7 @@ final class FlattenAndRemoveMixins {
             }
         }
 
-        if (!updatedShapes.isEmpty()) {
+        if (!updatedShapes.isEmpty() || !toRemove.isEmpty()) {
             Model.Builder builder = model.toBuilder();
             updatedShapes.forEach(builder::addShape);
             // Don't use the removeShapes transform because that would further mutate shapes and remove the things


Test patch:
diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ModelTransformerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ModelTransformerTest.java
index 3e54ff288..ee267e7b4 100644
--- a/smithy-model/src/test/java/software/amazon/smithy/model/transform/ModelTransformerTest.java
+++ b/smithy-model/src/test/java/software/amazon/smithy/model/transform/ModelTransformerTest.java
@@ -145,6 +145,36 @@ public class ModelTransformerTest {
                    Matchers.equalTo(concrete.toBuilder().flattenMixins().build()));
     }
 
+    @Test
+    public void canFilterAndRemoveMixinsWhenUnusedMixinsArePresent() {
+        ModelTransformer transformer = ModelTransformer.create();
+        Model.Builder builder = Model.builder();
+        StringShape string = StringShape.builder().id("smithy.example#String").build();
+        StructureShape mixin1 = StructureShape.builder()
+                .id("smithy.example#Mixin1")
+                .addTrait(MixinTrait.builder().build())
+                .addMember("a", string.getId())
+                .build();
+        StructureShape mixin2 = StructureShape.builder()
+                .id("smithy.example#Mixin2")
+                .addMember("b", string.getId())
+                .addTrait(MixinTrait.builder().build())
+                .build();
+        StructureShape mixin3 = StructureShape.builder()
+                .id("smithy.example#Mixin3")
+                .addMember("c", string.getId())
+                .addTrait(MixinTrait.builder().build())
+                .addMixin(mixin2)
+                .build();
+        builder.addShapes(mixin1, mixin2, mixin3);
+        Model model = builder.build();
+        Model result = transformer.flattenAndRemoveMixins(model);
+
+        assertThat(result.toSet(), Matchers.not(Matchers.hasItem(mixin1)));
+        assertThat(result.toSet(), Matchers.not(Matchers.hasItem(mixin2)));
+        assertThat(result.toSet(), Matchers.not(Matchers.hasItem(mixin3)));
+    }
+
     @ParameterizedTest
     @MethodSource("flattenShapesData")
     public void flattenShapes(String name) {