Skip to content

Commit

Permalink
Extract rule constants
Browse files Browse the repository at this point in the history
  • Loading branch information
pboos committed Oct 18, 2023
1 parent 0849c96 commit 9bcd6ed
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

@AllArgsConstructor
public class InternalViolationExclusions {
private static final String RULE_REQUEST_OPERATION_NOT_ALLOWED = "validation.request.operation.notAllowed";
private static final String RULE_REQUEST_BODY_SCHEMA_ONE_OF = "validation.request.body.schema.oneOf";
private static final String RULE_REQUEST_PATH_MISSING = "validation.request.path.missing";
private static final String RULE_RESPONSE_BODY_SCHEMA_ONE_OF = "validation.response.body.schema.oneOf";

private final ViolationExclusions customViolationExclusions;

public boolean isExcluded(OpenApiViolation violation) {
Expand All @@ -19,15 +24,15 @@ public boolean isExcluded(OpenApiViolation violation) {

private static boolean oneOfMatchesMoreThanOneSchema(OpenApiViolation violation) {
return (
"validation.response.body.schema.oneOf".equals(violation.getRule())
|| "validation.request.body.schema.oneOf".equals(violation.getRule())
RULE_RESPONSE_BODY_SCHEMA_ONE_OF.equals(violation.getRule())
|| RULE_REQUEST_BODY_SCHEMA_ONE_OF.equals(violation.getRule())
)
&& violation.getMessage()
.matches(".*Instance failed to match exactly one schema \\(matched [1-9][0-9]* out of \\d+\\).*");
}

private boolean falsePositive404(OpenApiViolation violation) {
return "validation.request.path.missing".equals(violation.getRule())
return RULE_REQUEST_PATH_MISSING.equals(violation.getRule())
&& (
violation.getDirection() == Direction.REQUEST
|| (violation.getDirection() == Direction.RESPONSE && violation.getResponseStatus().orElse(0) == 404)
Expand All @@ -40,6 +45,6 @@ private boolean falsePositive400(OpenApiViolation violation) {

private boolean falsePositive405(OpenApiViolation violation) {
return violation.getResponseStatus().orElse(0) == 405
&& "validation.request.operation.notAllowed".equals(violation.getRule());
&& RULE_REQUEST_OPERATION_NOT_ALLOWED.equals(violation.getRule());
}
}

0 comments on commit 9bcd6ed

Please sign in to comment.