Skip to content

Commit

Permalink
do not log request violation if shouldFailOnRequestViolation
Browse files Browse the repository at this point in the history
  • Loading branch information
pboos committed Nov 23, 2023
1 parent b6bcb9d commit 8857839
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public class OpenApiRequestValidationConfiguration {
private double sampleRate;
private int validationReportThrottleWaitSeconds;
private boolean shouldFailOnRequestViolation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class OpenApiRequestValidator {
private final ThreadPoolExecutor threadPoolExecutor;
private final OpenApiInteractionValidatorWrapper validator;
private final ValidationReportHandler validationReportHandler;
private final OpenApiRequestValidationConfiguration configuration;

public OpenApiRequestValidator(
ThreadPoolExecutor threadPoolExecutor,
Expand All @@ -34,6 +35,7 @@ public OpenApiRequestValidator(
this.threadPoolExecutor = threadPoolExecutor;
this.validator = validator;
this.validationReportHandler = validationReportHandler;
this.configuration = configuration;

metricsReporter.reportStartup(
validator != null,
Expand Down Expand Up @@ -74,7 +76,12 @@ public ValidationResult validateRequestObject(
try {
var simpleRequest = buildSimpleRequest(request, requestBody);
var result = validator.validateRequest(simpleRequest);
validationReportHandler.handleValidationReport(request, response, Direction.REQUEST, requestBody, result);
// TODO this should not be done here, but currently the only way to do it -> Refactor this so that logging
// is actually done in the interceptor/filter where logging can easily be skipped then.
if (!configuration.isShouldFailOnRequestViolation()) {
validationReportHandler
.handleValidationReport(request, response, Direction.REQUEST, requestBody, result);
}
return buildValidationResult(result);
} catch (Exception e) {
log.error("Could not validate request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public OpenApiRequestValidationConfiguration toOpenApiRequestValidationConfigura
return OpenApiRequestValidationConfiguration.builder()
.sampleRate(getSampleRate())
.validationReportThrottleWaitSeconds(getValidationReportThrottleWaitSeconds())
.shouldFailOnRequestViolation(getShouldFailOnRequestViolation())
.build();
}
}

0 comments on commit 8857839

Please sign in to comment.