Skip to content

bugfix: Exclude "matched 2 out of 25" in the oneOf rule #36

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

Merged
merged 4 commits into from
Aug 30, 2023
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 @@ -13,9 +13,16 @@ public boolean isExcluded(OpenApiViolation violation) {
return falsePositive404(violation)
|| falsePositive400(violation)
|| customViolationExclusions.isExcluded(violation)
// If it matches more than 1, then we don't want to log a validation error
|| violation.getMessage().matches(
".*\\[Path '[^']+'] Instance failed to match exactly one schema \\(matched [1-9][0-9]* out of \\d\\).*");
|| oneOfMatchesMoreThanOneSchema(violation);
}

private static boolean oneOfMatchesMoreThanOneSchema(OpenApiViolation violation) {
return (
"validation.response.body.schema.oneOf".equals(violation.getRule())
|| "validation.request.body.schema.oneOf".equals(violation.getRule())
)
&& violation.getMessage()
.matches(".*Instance failed to match exactly one schema \\(matched [1-9][0-9]* out of \\d+\\).*");
Comment on lines +20 to +25
Copy link
Contributor Author

@pboos pboos Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ I decided to also add the rules, to be safe.

}

private boolean falsePositive404(OpenApiViolation violation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,20 @@ public void testWhenInstanceFailedToMatchExactlyOneThenViolationExcluded() {
when(customViolationExclusions.isExcluded(any())).thenReturn(false);

checkViolationExcluded(OpenApiViolation.builder()
.rule("validation.response.body.schema.oneOf")
.message("[Path '/v1/endpoint'] Instance failed to match exactly one schema (matched 2 out of 4)").build());
}

@Test
public void testWhenInstanceFailedToMatchExactlyOneWithOneOf24ThenViolationExcluded() {
when(customViolationExclusions.isExcluded(any())).thenReturn(false);

checkViolationExcluded(OpenApiViolation.builder()
.rule("validation.request.body.schema.oneOf")
.message("[Path '/v1/endpoint'] Instance failed to match exactly one schema (matched 2 out of 24)")
.build());
}

@Test
public void testWhen404ResponseWithApiPathNotSpecifiedThenViolationExcluded() {
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
Expand Down