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

bugfix for validator ids and hierarchical subparts #1705

Merged
merged 1 commit into from
Mar 31, 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
@@ -0,0 +1,2 @@
[DANGER] smithy.example#GetFooInput: This structure is the input of `smithy.example#GetFoo`, but it is not marked with the @input trait. The @input trait gives operations more flexibility to evolve their top-level input members in ways that would otherwise be backward incompatible. | CustomInputOutputStructureReuse.Input.GetFoo
[DANGER] smithy.example#GetFooOutput: This structure is the output of `smithy.example#GetFoo`, but it is not marked with the @output trait. | CustomInputOutputStructureReuse.Output.GetFoo
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$version: "2.0"

metadata validators = [
{
name: "InputOutputStructureReuse",
id: "CustomInputOutputStructureReuse"
severity: "DANGER",
}
]

namespace smithy.example

operation GetFoo {
input: GetFooInput,
output: GetFooOutput
}

structure GetFooInput {}

structure GetFooOutput {}

operation GetBaz {
input: GetBazInput,
output: GetBazOutput
}

@input
structure GetBazInput {}

@output
structure GetBazOutput {}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ List<ValidationEvent> map(Model model, List<ValidationEvent> events) {
} else {
// Modify the event by changing the id, severity, or message.
ValidationEvent.Builder builder = event.toBuilder();
builder.id(id != null ? id : event.getId());
builder.id(replaceId(event.getId(), id));
builder.severity(severity != null ? severity : event.getSeverity());
if (message != null) {
builder.message(message.replace("{super}", event.getMessage()));
Expand All @@ -97,4 +97,13 @@ private boolean filterEvent(ValidationEvent event, Set<ShapeId> candidates) {

return true;
}

private String replaceId(String eventId, String validatorId) {
int index = eventId.indexOf(".");
if (index == -1) {
return validatorId;
} else {
return validatorId + eventId.substring(index);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Optional<Validator> createValidator(String name, ObjectNode configuration
? Optional.of(
model -> model.shapes()
.map(shape -> ValidationEvent.builder()
.id(name)
.id("hello.subpart")
.shape(shape)
.severity(Severity.WARNING)
.message("Hello!")
Expand All @@ -48,12 +48,12 @@ public Optional<Validator> createValidator(String name, ObjectNode configuration
.getValidationEvents();

assertThat(events, not(empty()));
Assertions.assertEquals(2, events.stream().filter(e -> e.getId().equals("hello")).count());
Assertions.assertEquals(4, events.stream().filter(e -> e.getId().equals("custom")).count());
Assertions.assertEquals(2, events.stream().filter(e -> e.getId().equals("hello.subpart")).count());
Assertions.assertEquals(4, events.stream().filter(e -> e.getId().equals("customHello.subpart")).count());

// Ensure that template expansion works.
for (ValidationEvent event : events) {
if (event.getId().equals("custom")) {
if (event.getId().equals("customHello.subpart")) {
assertThat(event.getMessage(), equalTo("Test Hello!"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata validators = [
},
{ // Picks up 4 shapes
name: "hello",
id: "custom",
id: "customHello",
message: "Test {super}"
},
]
Expand Down