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

Extend event ids for Added/RemovedOperationError events #1803

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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;

/**
Expand All @@ -42,15 +43,23 @@ private List<ValidationEvent> createErrorViolations(ChangedShape<OperationShape>
}

List<ValidationEvent> 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)
.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())
.sourceLocation(change.getNewShape().getSourceLocation())
rchache marked this conversation as resolved.
Show resolved Hide resolved
.build()
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -42,11 +43,19 @@ private List<ValidationEvent> createErrorViolations(ChangedShape<OperationShape>
}

List<ValidationEvent> 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)
.severity(Severity.WARNING)
.message(String.format(
"The `%s` error was removed from the `%s` operation.",
error, change.getShapeId()))
.shape(change.getNewShape())
.sourceLocation(change.getNewShape().getSourceLocation())
.build()
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ public void detectsAddedErrors() {
List<ValidationEvent> events = ModelDiff.compare(modelA, modelB);

assertThat(TestHelper.findEvents(events, "AddedOperationError").size(), equalTo(2));
assertThat(TestHelper.findEvents(events, "AddedOperationError.foo.baz#E1").size(), equalTo(1));
assertThat(TestHelper.findEvents(events, "AddedOperationError.foo.baz#E2").size(), equalTo(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.foo.baz#E1").size(), equalTo(1));
rchache marked this conversation as resolved.
Show resolved Hide resolved
assertThat(TestHelper.findEvents(events, "RemovedOperationError.foo.baz#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"));
Expand Down