Skip to content

Commit

Permalink
Remove optional wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase committed Aug 31, 2023
1 parent a378fdb commit 38beb19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,29 +170,27 @@ public Optional<ErrorExample> getError() {
/**
* @return Gets the list of lowered input validation severities.
*/
public Optional<List<NodeValidationVisitor.Feature>> getLowerInputValidationSeverity() {
return Optional.ofNullable(lowerInputValidationSeverity);
public List<NodeValidationVisitor.Feature> getLowerInputValidationSeverity() {
return lowerInputValidationSeverity;
}

@Override
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);
}
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ private List<ValidationEvent> 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.",
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 38beb19

Please sign in to comment.