diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedOperationError.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedOperationError.java index bbf612801ef..1f431156c86 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedOperationError.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/AddedOperationError.java @@ -23,6 +23,7 @@ import software.amazon.smithy.diff.Differences; import software.amazon.smithy.model.shapes.OperationShape; import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.validation.Severity; import software.amazon.smithy.model.validation.ValidationEvent; /** @@ -42,15 +43,22 @@ private List createErrorViolations(ChangedShape } List events = new ArrayList<>(); - for (ShapeId id : change.getNewShape().getErrors()) { - if (!change.getOldShape().getErrors().contains(id)) { - events.add(warning(change.getNewShape(), String.format( - "The `%s` error was added to the `%s` operation. This " - + "is backward-compatible if the error is only " - + "encountered as a result of a change in behavior of " - + "the client (for example, the client sends a new " - + "parameter to an operation).", - id, change.getShapeId()))); + for (ShapeId error : change.getNewShape().getErrors()) { + if (!change.getOldShape().getErrors().contains(error)) { + events.add( + ValidationEvent.builder() + .id(getEventId() + "." + error.getName()) + .severity(Severity.WARNING) + .message(String.format( + "The `%s` error was added to the `%s` operation. This " + + "is backward-compatible if the error is only " + + "encountered as a result of a change in behavior of " + + "the client (for example, the client sends a new " + + "parameter to an operation).", + error, change.getShapeId())) + .shape(change.getNewShape()) + .build() + ); } } diff --git a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedOperationError.java b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedOperationError.java index b66c05c2d03..ca3a7fa0ba2 100644 --- a/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedOperationError.java +++ b/smithy-diff/src/main/java/software/amazon/smithy/diff/evaluators/RemovedOperationError.java @@ -23,6 +23,7 @@ import software.amazon.smithy.diff.Differences; import software.amazon.smithy.model.shapes.OperationShape; import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.validation.Severity; import software.amazon.smithy.model.validation.ValidationEvent; /** @@ -42,11 +43,18 @@ private List createErrorViolations(ChangedShape } List events = new ArrayList<>(); - for (ShapeId id : change.getOldShape().getErrors()) { - if (!change.getNewShape().getErrors().contains(id)) { - events.add(warning(change.getNewShape(), String.format( - "The `%s` error was removed from the `%s` operation.", - id, change.getShapeId()))); + for (ShapeId error : change.getOldShape().getErrors()) { + if (!change.getNewShape().getErrors().contains(error)) { + events.add( + ValidationEvent.builder() + .id(getEventId() + "." + error.getName()) + .severity(Severity.WARNING) + .message(String.format( + "The `%s` error was removed from the `%s` operation.", + error, change.getShapeId())) + .shape(change.getNewShape()) + .build() + ); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedOperationErrorTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedOperationErrorTest.java index bbebcb6ed90..38fa859a307 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedOperationErrorTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/AddedOperationErrorTest.java @@ -46,5 +46,7 @@ public void detectsAddedErrors() { List events = ModelDiff.compare(modelA, modelB); assertThat(TestHelper.findEvents(events, "AddedOperationError").size(), equalTo(2)); + assertThat(TestHelper.findEvents(events, "AddedOperationError.E1").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "AddedOperationError.E2").size(), equalTo(1)); } } diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedOperationErrorTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedOperationErrorTest.java index 5d7f8cc9611..3c6ff908afb 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedOperationErrorTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/RemovedOperationErrorTest.java @@ -52,6 +52,8 @@ public void detectsRemovedErrors() { // Emits an event for each removal. assertThat(TestHelper.findEvents(events, "RemovedOperationError").size(), equalTo(2)); + assertThat(TestHelper.findEvents(events, "RemovedOperationError.E1").size(), equalTo(1)); + assertThat(TestHelper.findEvents(events, "RemovedOperationError.E2").size(), equalTo(1)); assertThat(TestHelper.findEvents(events, "RemovedOperationError").get(0).toString(), startsWith("[WARNING] foo.baz#Operation: The `foo.baz#E1` error was removed " + "from the `foo.baz#Operation` operation. | RemovedOperationError"));