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 duplicated events for ChangedNullability Added/RemovedInputTrait #1806

Merged
merged 1 commit into from
Jun 8, 2023
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 @@ -16,8 +16,11 @@
package software.amazon.smithy.diff.evaluators;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;
import software.amazon.smithy.diff.ChangedShape;
import software.amazon.smithy.diff.Differences;
Expand Down Expand Up @@ -45,7 +48,7 @@ public class ChangedNullability extends AbstractDiffEvaluator {
public List<ValidationEvent> evaluate(Differences differences) {
NullableIndex oldIndex = NullableIndex.of(differences.getOldModel());
NullableIndex newIndex = NullableIndex.of(differences.getNewModel());
List<ValidationEvent> events = new ArrayList<>();
Set<ValidationEvent> events = new HashSet<>();

Stream.concat(
// Get members that changed.
Expand All @@ -63,7 +66,7 @@ public List<ValidationEvent> evaluate(Differences differences) {
}
});

return events;
return new ArrayList<>(events);
}

private Stream<ChangedShape<MemberShape>> changedInputMembers(Differences differences) {
Expand All @@ -82,7 +85,7 @@ private void createErrors(
Differences differences,
ChangedShape<MemberShape> change,
boolean wasNullable,
List<ValidationEvent> events
Collection<ValidationEvent> events
) {
MemberShape oldMember = change.getOldShape();
MemberShape newMember = change.getNewShape();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import software.amazon.smithy.model.traits.BoxTrait;
import software.amazon.smithy.model.traits.ClientOptionalTrait;
import software.amazon.smithy.model.traits.DefaultTrait;
import software.amazon.smithy.model.traits.DocumentationTrait;
import software.amazon.smithy.model.traits.InputTrait;
import software.amazon.smithy.model.traits.RequiredTrait;
import software.amazon.smithy.model.transform.ModelTransformer;
Expand Down Expand Up @@ -188,16 +189,18 @@ public void detectAdditionOfNullableTrait() {

@Test
public void detectsAdditionOfInputTrait() {
MemberShape member = MemberShape.builder()
MemberShape member1 = MemberShape.builder()
.id("foo.baz#Baz$bam")
.target("foo.baz#String")
.addTrait(new RequiredTrait())
.build();
StructureShape shapeA1 = StructureShape.builder().id("foo.baz#Baz").addMember(member).build();
StructureShape shapeA2 = shapeA1.toBuilder().addTrait(new InputTrait()).build();
MemberShape member2 = member1.toBuilder().addTrait(new DocumentationTrait("docs")).build();
StructureShape shapeA1 = StructureShape.builder().id("foo.baz#Baz").addMember(member1).build();
StructureShape shapeA2 = StructureShape.builder().id("foo.baz#Baz").addMember(member2)
.addTrait(new InputTrait()).build();
StringShape target = StringShape.builder().id("foo.baz#String").build();
Model modelA = Model.assembler().addShapes(shapeA1, member, target).assemble().unwrap();
Model modelB = Model.assembler().addShapes(shapeA2, member, target).assemble().unwrap();
Model modelA = Model.assembler().addShapes(shapeA1, member1, target).assemble().unwrap();
Model modelB = Model.assembler().addShapes(shapeA2, member2, target).assemble().unwrap();
List<ValidationEvent> events = ModelDiff.compare(modelA, modelB);

assertThat(events.stream()
Expand All @@ -209,19 +212,26 @@ public void detectsAdditionOfInputTrait() {

@Test
public void detectsRemovalOfInputTrait() {
MemberShape member = MemberShape.builder()
MemberShape member1 = MemberShape.builder()
.id("foo.baz#Baz$bam")
.target("foo.baz#String")
.addTrait(new RequiredTrait())
.build();
MemberShape member2 = member1.toBuilder()
.addTrait(new DocumentationTrait("docs"))
.build();
StructureShape shapeA1 = StructureShape.builder()
.id("foo.baz#Baz").addMember(member)
.id("foo.baz#Baz")
.addMember(member1)
.addTrait(new InputTrait())
.build();
StructureShape shapeA2 = shapeA1.toBuilder().removeTrait(InputTrait.ID).build();
StructureShape shapeA2 = StructureShape.builder()
.id("foo.baz#Baz")
.addMember(member2)
.build();
StringShape target = StringShape.builder().id("foo.baz#String").build();
Model modelA = Model.assembler().addShapes(shapeA1, member, target).assemble().unwrap();
Model modelB = Model.assembler().addShapes(shapeA2, member, target).assemble().unwrap();
Model modelA = Model.assembler().addShapes(shapeA1, member1, target).assemble().unwrap();
Model modelB = Model.assembler().addShapes(shapeA2, member2, target).assemble().unwrap();
List<ValidationEvent> events = ModelDiff.compare(modelA, modelB);

assertThat(events.stream()
Expand Down