Skip to content

Commit

Permalink
[Bugfix] Ignore violation operation not allowed with status code 404 (
Browse files Browse the repository at this point in the history
  • Loading branch information
pboos authored Oct 20, 2023
1 parent b3f0c2d commit 7565dd0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ private static boolean oneOfMatchesMoreThanOneSchema(OpenApiViolation violation)
}

private boolean falsePositive404(OpenApiViolation violation) {
return Rules.Request.PATH_MISSING.equals(violation.getRule())
&& (
violation.getDirection() == Direction.REQUEST
|| (violation.getDirection() == Direction.RESPONSE && violation.getResponseStatus().orElse(0) == 404)
return
(
Rules.Request.PATH_MISSING.equals(violation.getRule())
|| Rules.Request.OPERATION_NOT_ALLOWED.equals(violation.getRule())
) && (
(violation.getDirection() == Direction.REQUEST && violation.getResponseStatus().isEmpty())
|| violation.getResponseStatus().orElse(0) == 404
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ public void when404ResponseWithApiPathNotSpecifiedThenViolationExcluded() {
.build());
}

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

checkViolationExcluded(OpenApiViolation.builder()
.direction(Direction.RESPONSE)
.rule("validation.request.operation.notAllowed")
.responseStatus(404)
.message("GET operation not allowed on path '/users'")
.build());
}

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

checkViolationExcluded(OpenApiViolation.builder()
.direction(Direction.REQUEST)
.rule("validation.request.operation.notAllowed")
.message("GET operation not allowed on path '/users'")
.build());
}

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

0 comments on commit 7565dd0

Please sign in to comment.