Skip to content

Commit cc43422

Browse files
committed
fix(core): exclude accept.notAllowed violations on 204 responses
The client controls the request Accept header, and a 204 response has no body. Add Rules.Request.ACCEPT_NOT_ALLOWED and exclude it when the response status is 204. Other statuses and rules are still reported (TRX-1066).
1 parent d17e632 commit cc43422

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎openapi-validation-api/src/main/java/com/getyourguide/openapi/validation/api/Rules.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public static class Request {
55
public static final String PATH_MISSING = "validation.request.path.missing";
66
public static final String OPERATION_NOT_ALLOWED = "validation.request.operation.notAllowed";
77
public static final String BODY_SCHEMA_ONE_OF = "validation.request.body.schema.oneOf";
8+
public static final String ACCEPT_NOT_ALLOWED = "validation.request.accept.notAllowed";
89
}
910

1011
public static class Response {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class InternalViolationExclusions {
1212
private final ViolationExclusions customViolationExclusions;
1313

1414
public boolean isExcluded(OpenApiViolation violation) {
15-
return falsePositive404(violation)
15+
return falsePositive204(violation)
16+
|| falsePositive404(violation)
1617
|| falsePositive405(violation)
1718
|| falsePositive406(violation)
1819
|| falsePositiveRequestWith4xxResponse(violation)
@@ -31,6 +32,11 @@ private static boolean oneOfMatchesMoreThanOneSchema(OpenApiViolation violation)
3132
.matches(".*Instance failed to match exactly one schema \\(matched [1-9][0-9]* out of \\d+\\).*");
3233
}
3334

35+
private boolean falsePositive204(OpenApiViolation violation) {
36+
return violation.getResponseStatus().orElse(0) == 204
37+
&& Rules.Request.ACCEPT_NOT_ALLOWED.equals(violation.getRule());
38+
}
39+
3440
private boolean falsePositive404(OpenApiViolation violation) {
3541
return
3642
(

0 commit comments

Comments
 (0)