Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ModifiedTrait for traits with breaking change rules #2249

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ private static Map<ShapeId, List<DiffStrategy>> computeDiffStrategies(Model mode
List<DiffStrategy> 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()) {
syall marked this conversation as resolved.
Show resolved Hide resolved
// Avoid duplicate validation events; delegate emitting events to TraitBreakingChange.
result.put(shape.getId(), Collections.emptyList());
} else {
result.put(shape.getId(), DEFAULT_STRATEGIES);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ structure aTrait {

@tags(["diff.warning.const"])
l: String,

@tags(["diff.contents"])
m: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ structure aTrait {

@tags(["diff.warning.const"])
l: String,

@tags(["diff.contents"])
m: String,
}
Loading