Skip to content

Commit 240f93c

Browse files
committed
feature: Ignore violation if request violation with 4xx response status
1 parent 2004377 commit 240f93c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class InternalViolationExclusions {
1313

1414
public boolean isExcluded(OpenApiViolation violation) {
1515
return falsePositive404(violation)
16-
|| falsePositive400(violation)
1716
|| falsePositive405(violation)
1817
|| falsePositive406(violation)
18+
|| falsePositiveRequestWith4xxResponse(violation)
1919
|| customViolationExclusions.isExcluded(violation)
2020
|| oneOfMatchesMoreThanOneSchema(violation);
2121
}
@@ -40,8 +40,10 @@ private boolean falsePositive404(OpenApiViolation violation) {
4040
);
4141
}
4242

43-
private boolean falsePositive400(OpenApiViolation violation) {
44-
return violation.getDirection() == Direction.REQUEST && violation.getResponseStatus().orElse(0) == 400;
43+
private boolean falsePositiveRequestWith4xxResponse(OpenApiViolation violation) {
44+
return violation.getDirection() == Direction.REQUEST
45+
&& violation.getResponseStatus().orElse(0) >= 400
46+
&& violation.getResponseStatus().orElse(0) < 500;
4547
}
4648

4749
private boolean falsePositive405(OpenApiViolation violation) {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,16 @@ public void whenRequestWithApiPathNotSpecifiedThenViolationExcluded() {
116116
}
117117

118118
@Test
119-
public void whenRequestViolationsAnd400ThenViolationExcluded() {
119+
public void whenRequestViolationsAnd4xxThenViolationExcluded() {
120120
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
121121

122-
checkViolationExcluded(OpenApiViolation.builder()
123-
.direction(Direction.REQUEST)
124-
.responseStatus(400)
125-
.message("")
126-
.build());
122+
for (int responseStatus = 400; responseStatus < 500; responseStatus++) {
123+
checkViolationExcluded(OpenApiViolation.builder()
124+
.direction(Direction.REQUEST)
125+
.responseStatus(responseStatus)
126+
.message("")
127+
.build());
128+
}
127129
}
128130

129131
@Test

0 commit comments

Comments
 (0)