Skip to content

Commit

Permalink
bugfix: exclude 406 status code violations
Browse files Browse the repository at this point in the history
  • Loading branch information
pboos committed Nov 1, 2023
1 parent 98d1a8d commit 9c129df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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

0 comments on commit 9c129df

Please sign in to comment.