diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java index f53510fe79e..d153bb3783f 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/traits/ExamplesTrait.java @@ -170,8 +170,8 @@ public Optional getError() { /** * @return Gets the list of lowered input validation severities. */ - public Optional> getLowerInputValidationSeverity() { - return Optional.ofNullable(lowerInputValidationSeverity); + public List getLowerInputValidationSeverity() { + return lowerInputValidationSeverity; } @Override @@ -179,7 +179,11 @@ public Node toNode() { ObjectNode.Builder builder = Node.objectNodeBuilder() .withMember("title", Node.from(title)) .withOptionalMember("documentation", getDocumentation().map(Node::from)) - .withOptionalMember("error", getError().map(ErrorExample::toNode)); + .withOptionalMember("error", getError().map(ErrorExample::toNode)) + .withMember("lowerInputValidationSeverity", ArrayNode.fromNodes(lowerInputValidationSeverity + .stream() + .map(NodeValidationVisitor.Feature::toNode) + .collect(Collectors.toList()))); if (!input.isEmpty()) { builder.withMember("input", input); @@ -187,12 +191,6 @@ public Node toNode() { if (this.getOutput().isPresent()) { builder.withMember("output", output); } - if (this.getLowerInputValidationSeverity().isPresent()) { - builder.withMember("lowerInputValidationSeverity", ArrayNode.fromNodes(lowerInputValidationSeverity - .stream() - .map(NodeValidationVisitor.Feature::toNode) - .collect(Collectors.toList()))); - } return builder.build(); } diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java index 3f70e414dba..97959e5cdd6 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ExamplesTraitValidator.java @@ -69,8 +69,7 @@ private List validateExamples(Model model, OperationShape shape model.getShape(shape.getInputShape()).ifPresent(input -> { NodeValidationVisitor validator; - if (example.getLowerInputValidationSeverity().isPresent() - && !example.getLowerInputValidationSeverity().get().isEmpty()) { + if (!example.getLowerInputValidationSeverity().isEmpty()) { if (!isErrorDefined) { events.add(error(shape, trait, String.format( "Example: `%s` has lowerInputValidationSeverity defined, so error must also be defined.", @@ -127,9 +126,9 @@ private NodeValidationVisitor createVisitor( .startingContext("Example " + name + " of `" + example.getTitle() + "`") .eventId(getName()); if (enableFeatures) { - example.getLowerInputValidationSeverity().ifPresent(features -> features.stream() + example.getLowerInputValidationSeverity().stream() .filter(ALLOWED_FEATURES::contains) - .forEach(builder::addFeature)); + .forEach(builder::addFeature); } return builder.build(); }