Skip to content

Commit

Permalink
Fix an NPE when validating an examples trait
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Nov 25, 2020
1 parent 622089b commit 705efff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public static Builder builder() {
public static final class Builder implements SmithyBuilder<Example> {
private String title;
private String documentation;
private ObjectNode input;
private ObjectNode output;
private ObjectNode input = Node.objectNode();
private ObjectNode output = Node.objectNode();

@Override
public Example build() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package software.amazon.smithy.model.validation;

import org.junit.jupiter.api.Test;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.traits.ExamplesTrait;
import software.amazon.smithy.model.validation.validators.ExamplesTraitValidator;

public class ExamplesTraitValidatorTest {
// There was an NPE previously due to the input/output values
// in the builder for an ExamplesTrait.Example not being
// initialized to an empty ObjectNode.
@Test
public void noNpeWhenInputOrOutputAreOmitted() {
ExamplesTrait.Example example = ExamplesTrait.Example.builder()
.title("Title")
.documentation("Documentation")
.build();
ExamplesTrait trait = ExamplesTrait.builder().addExample(example).build();
Shape shape = OperationShape.builder()
.id("foo.bar#Baz")
.addTrait(trait)
.build();
Model model = Model.builder().addShape(shape).build();

ExamplesTraitValidator validator = new ExamplesTraitValidator();

// Just make sure it doesn't throw.
validator.validate(model);
}
}

0 comments on commit 705efff

Please sign in to comment.