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 an NPE when validating an examples trait #642

Merged
merged 1 commit into from
Nov 25, 2020
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 @@ -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);
}
}