-
Notifications
You must be signed in to change notification settings - Fork 218
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
Modifies ExamplesTraitValidator to handle cases where both output and error are defined #1599
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,13 +53,20 @@ private List<ValidationEvent> validateExamples(Model model, OperationShape shape | |
events.addAll(input.accept(validator)); | ||
}); | ||
|
||
model.getShape(shape.getOutputShape()).ifPresent(output -> { | ||
NodeValidationVisitor validator = createVisitor( | ||
"output", example.getOutput(), model, shape, example); | ||
events.addAll(output.accept(validator)); | ||
}); | ||
boolean isOutputDefined = example.getOutput().isPresent(); | ||
boolean isErrorDefined = example.getError().isPresent(); | ||
|
||
if (example.getError().isPresent()) { | ||
if (isOutputDefined && isErrorDefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is the behaviour we want, this needs to be mentioned in the doc as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great point! |
||
events.add(error(shape, trait, String.format( | ||
"Example: `%s` has both output and error defined, only one should be present.", | ||
example.getTitle()))); | ||
} else if (isOutputDefined) { | ||
model.getShape(shape.getOutputShape()).ifPresent(output -> { | ||
NodeValidationVisitor validator = createVisitor( | ||
"output", example.getOutput().get(), model, shape, example); | ||
events.addAll(output.accept(validator)); | ||
}); | ||
} else if (isErrorDefined) { | ||
ExamplesTrait.ErrorExample errorExample = example.getError().get(); | ||
Optional<Shape> errorShape = model.getShape(errorExample.getShapeId()); | ||
if (errorShape.isPresent() && shape.getErrors().contains(errorExample.getShapeId())) { | ||
|
@@ -68,7 +75,7 @@ private List<ValidationEvent> validateExamples(Model model, OperationShape shape | |
events.addAll(errorShape.get().accept(validator)); | ||
} else { | ||
events.add(error(shape, trait, String.format( | ||
"Error parameters provided for operation without the `%s` error: `%s`", | ||
"Error parameters provided for operation without the `%s` error: `%s`", | ||
errorExample.getShapeId(), example.getTitle()))); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of a breaking change... but maybe using this trait in code is fringe enough to not matter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about keeping it as is and checking if
example.getOutput().isEmpty()
to check if it was defined, but it opened the possibility of the example below being valid, which I think shouldn't be, if it's present it should conform, even if empty: