Skip to content

Commit 71039fa

Browse files
authored
Exclude library internal exception unhandled token type NOT_AVAILABLE (#228)
1 parent 6571c26 commit 71039fa

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public boolean isExcluded(OpenApiViolation violation) {
1818
|| falsePositiveRequestWith4xxResponse(violation)
1919
|| customViolationExclusions.isExcluded(violation)
2020
|| oneOfMatchesMoreThanOneSchema(violation)
21-
|| isConcurrentModificationExceptionInLibrary(violation);
21+
|| isConcurrentModificationExceptionInLibrary(violation)
22+
|| isUnhandledUncheckedExecutionExceptionInLibrary(violation);
2223
}
2324

2425
private static boolean oneOfMatchesMoreThanOneSchema(OpenApiViolation violation) {
@@ -61,4 +62,10 @@ private boolean isConcurrentModificationExceptionInLibrary(OpenApiViolation viol
6162
return violation.getRule() != null && violation.getRule().endsWith(".body.schema.unknownError")
6263
&& violation.getMessage().contains("java.util.ConcurrentModificationException");
6364
}
65+
66+
private boolean isUnhandledUncheckedExecutionExceptionInLibrary(OpenApiViolation violation) {
67+
return violation.getRule() != null && violation.getRule().endsWith(".body.schema.unknownError")
68+
&& violation.getMessage().contains("UncheckedExecutionException")
69+
&& violation.getMessage().contains("unhandled token type NOT_AVAILABLE");
70+
}
6471
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ public void whenUnknownErrorWithConcurrentModificationExceptionThenViolationExcl
179179
.build());
180180
}
181181

182+
@Test
183+
public void whenUnknownErrorWithNotAvailableTokenThenViolationExcluded() {
184+
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
185+
String message =
186+
"An error occurred during schema validation - com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException: unhandled token type NOT_AVAILABLE.";
187+
188+
checkViolationExcluded(OpenApiViolation.builder()
189+
.direction(Direction.RESPONSE)
190+
.rule("validation.request.body.schema.unknownError")
191+
.responseStatus(200)
192+
.message(message)
193+
.build());
194+
checkViolationExcluded(OpenApiViolation.builder()
195+
.direction(Direction.RESPONSE)
196+
.rule("validation.response.body.schema.unknownError")
197+
.responseStatus(200)
198+
.message(message)
199+
.build());
200+
}
201+
182202
private void checkViolationNotExcluded(OpenApiViolation violation) {
183203
var isExcluded = violationExclusions.isExcluded(violation);
184204

0 commit comments

Comments
 (0)