Skip to content

bugfix: exclude 406 status code violations #48

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 1 commit into from
Nov 1, 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 @@ -9,5 +9,6 @@ public static class Request {

public static class Response {
public static final String BODY_SCHEMA_ONE_OF = "validation.response.body.schema.oneOf";
public static final String STATUS_UNKNOWN = "validation.response.status.unknown";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public boolean isExcluded(OpenApiViolation violation) {
return falsePositive404(violation)
|| falsePositive400(violation)
|| falsePositive405(violation)
|| falsePositive406(violation)
|| customViolationExclusions.isExcluded(violation)
|| oneOfMatchesMoreThanOneSchema(violation);
}
Expand Down Expand Up @@ -47,4 +48,9 @@ private boolean falsePositive405(OpenApiViolation violation) {
return violation.getResponseStatus().orElse(0) == 405
&& Rules.Request.OPERATION_NOT_ALLOWED.equals(violation.getRule());
}

private boolean falsePositive406(OpenApiViolation violation) {
return violation.getResponseStatus().orElse(0) == 406
&& Rules.Response.STATUS_UNKNOWN.equals(violation.getRule());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ public void when405ResponseCodeWithOperationNotAllowedViolationThenViolationExcl
.build());
}

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

checkViolationExcluded(OpenApiViolation.builder()
.direction(Direction.RESPONSE)
.rule("validation.response.status.unknown")
.responseStatus(406)
.message("")
.build());
}

private void checkViolationNotExcluded(OpenApiViolation violation) {
var isExcluded = violationExclusions.isExcluded(violation);

Expand Down