diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java index ec41e2667b8..611d1b1aefd 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/ModifiedTrait.java @@ -145,8 +145,10 @@ private static Map> computeDiffStrategies(Model mode List strategies = createStrategiesForShape(shape, true); if (!strategies.isEmpty()) { result.put(shape.getId(), strategies); - } else if (definition.getBreakingChanges().isEmpty()) { - // Avoid duplicate validation events; only perform the default validation when there are no diff rules. + } else if (!definition.getBreakingChanges().isEmpty()) { + // Avoid duplicate validation events; delegate emitting events to TraitBreakingChange. + result.put(shape.getId(), Collections.emptyList()); + } else { result.put(shape.getId(), DEFAULT_STRATEGIES); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java index 5e0aa9f6cf2..ebbac8d488b 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java @@ -36,6 +36,7 @@ import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.StringShape; import software.amazon.smithy.model.traits.DynamicTrait; +import software.amazon.smithy.model.traits.JsonNameTrait; import software.amazon.smithy.model.traits.RequiredTrait; import software.amazon.smithy.model.traits.TagsTrait; import software.amazon.smithy.model.traits.TraitDefinition; @@ -366,4 +367,23 @@ public void letsOtherValidatorsHandleRequiredTrait() { assertThat(TestHelper.findEvents(ModelDiff.compare(oldModel, newModel), "ModifiedTrait"), empty()); } + + @Test + public void letsTraitBreakingChangeHandleDiffEvents() { + String originalModel = + "$version: \"2.0\"\n" + + "namespace smithy.example\n" + + "structure Test {\n" + + " @jsonName(\"a\")\n" + + " member: String\n" + + "}"; + Model oldModel = Model.assembler().addUnparsedModel("foo.smithy", originalModel).assemble().unwrap(); + Model newModel = ModelTransformer.create().replaceShapes(oldModel, ListUtils.of( + Shape.shapeToBuilder(oldModel.expectShape(ShapeId.from("smithy.example#Test$member"))) + .removeTrait(JsonNameTrait.ID) + .build())); + + assertThat(TestHelper.findEvents(ModelDiff.compare(oldModel, newModel), "ModifiedTrait"), empty()); + assertThat(TestHelper.findEvents(ModelDiff.compare(oldModel, newModel), "TraitBreakingChange"), hasSize(1)); + } } diff --git a/smithy-diff/src/test/resources/software/amazon/smithy/diff/evaluators/trait-modified-all-severities-a.smithy b/smithy-diff/src/test/resources/software/amazon/smithy/diff/evaluators/trait-modified-all-severities-a.smithy index 495e4b8ff5c..d1673fc350b 100644 --- a/smithy-diff/src/test/resources/software/amazon/smithy/diff/evaluators/trait-modified-all-severities-a.smithy +++ b/smithy-diff/src/test/resources/software/amazon/smithy/diff/evaluators/trait-modified-all-severities-a.smithy @@ -56,4 +56,7 @@ structure aTrait { @tags(["diff.warning.const"]) l: String, + + @tags(["diff.contents"]) + m: String, } diff --git a/smithy-diff/src/test/resources/software/amazon/smithy/diff/evaluators/trait-modified-all-severities-b.smithy b/smithy-diff/src/test/resources/software/amazon/smithy/diff/evaluators/trait-modified-all-severities-b.smithy index 339dc7a5a06..a73fe9dc701 100644 --- a/smithy-diff/src/test/resources/software/amazon/smithy/diff/evaluators/trait-modified-all-severities-b.smithy +++ b/smithy-diff/src/test/resources/software/amazon/smithy/diff/evaluators/trait-modified-all-severities-b.smithy @@ -56,4 +56,7 @@ structure aTrait { @tags(["diff.warning.const"]) l: String, + + @tags(["diff.contents"]) + m: String, }