Skip to content

Commit 7565dd0

Browse files
authored
[Bugfix] Ignore violation operation not allowed with status code 404 (#45)
1 parent b3f0c2d commit 7565dd0

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

openapi-validation-core/src/main/java/com/getyourguide/openapi/validation/core/exclusions/InternalViolationExclusions.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ private static boolean oneOfMatchesMoreThanOneSchema(OpenApiViolation violation)
2929
}
3030

3131
private boolean falsePositive404(OpenApiViolation violation) {
32-
return Rules.Request.PATH_MISSING.equals(violation.getRule())
33-
&& (
34-
violation.getDirection() == Direction.REQUEST
35-
|| (violation.getDirection() == Direction.RESPONSE && violation.getResponseStatus().orElse(0) == 404)
32+
return
33+
(
34+
Rules.Request.PATH_MISSING.equals(violation.getRule())
35+
|| Rules.Request.OPERATION_NOT_ALLOWED.equals(violation.getRule())
36+
) && (
37+
(violation.getDirection() == Direction.REQUEST && violation.getResponseStatus().isEmpty())
38+
|| violation.getResponseStatus().orElse(0) == 404
3639
);
3740
}
3841

openapi-validation-core/src/test/java/com/getyourguide/openapi/validation/core/exclusions/InternalViolationExclusionsTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ public void when404ResponseWithApiPathNotSpecifiedThenViolationExcluded() {
8080
.build());
8181
}
8282

83+
@Test
84+
public void when404ResponseWithOperationNotAllowedThenViolationExcluded() {
85+
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
86+
87+
checkViolationExcluded(OpenApiViolation.builder()
88+
.direction(Direction.RESPONSE)
89+
.rule("validation.request.operation.notAllowed")
90+
.responseStatus(404)
91+
.message("GET operation not allowed on path '/users'")
92+
.build());
93+
}
94+
95+
@Test
96+
public void when404RequestWithOperationNotAllowedThenViolationExcluded() {
97+
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
98+
99+
checkViolationExcluded(OpenApiViolation.builder()
100+
.direction(Direction.REQUEST)
101+
.rule("validation.request.operation.notAllowed")
102+
.message("GET operation not allowed on path '/users'")
103+
.build());
104+
}
105+
83106
@Test
84107
public void whenRequestWithApiPathNotSpecifiedThenViolationExcluded() {
85108
when(customViolationExclusions.isExcluded(any())).thenReturn(false);

0 commit comments

Comments
 (0)