Skip to content

Fix problem with validating partial bodies instead of whole body #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ private OpenApiViolation buildOpenApiViolation(
private boolean isViolationExcluded(OpenApiViolation openApiViolation) {
return
violationExclusions.isExcluded(openApiViolation)
// JSON parse errors should be ignored as it can't be compared to the schema then (this also prevents logging personal data!)
|| openApiViolation.getMessage().startsWith("Unable to parse JSON")
// If it matches more than 1, then we don't want to log a validation error
|| openApiViolation.getMessage().matches(
".*\\[Path '[^']+'] Instance failed to match exactly one schema \\(matched [1-9][0-9]* out of \\d\\).*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import org.springframework.lang.NonNull;
import reactor.core.publisher.Flux;
import reactor.core.publisher.SignalType;

public class BodyCachingServerHttpRequestDecorator extends ServerHttpRequestDecorator {
private final TrafficSelector trafficSelector;
Expand Down Expand Up @@ -38,11 +39,17 @@ public Flux<DataBuffer> getBody() {
return super.getBody();
}

return super.getBody().doOnNext(dataBuffer -> {
cachedBody = dataBuffer.toString(StandardCharsets.UTF_8);
if (onBodyCachedListener != null) {
onBodyCachedListener.run();
}
});
return super.getBody()
.doOnNext(dataBuffer -> {
if (cachedBody == null) {
cachedBody = "";
}
cachedBody += dataBuffer.toString(StandardCharsets.UTF_8);
})
.doFinally(signalType -> {
if (signalType == SignalType.ON_COMPLETE && onBodyCachedListener != null) {
onBodyCachedListener.run();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import org.springframework.lang.NonNull;
import reactor.core.publisher.Flux;
import reactor.core.publisher.SignalType;

public class BodyCachingServerHttpRequestDecorator extends ServerHttpRequestDecorator {
private final TrafficSelector trafficSelector;
Expand Down Expand Up @@ -38,11 +39,17 @@ public Flux<DataBuffer> getBody() {
return super.getBody();
}

return super.getBody().doOnNext(dataBuffer -> {
cachedBody = dataBuffer.toString(StandardCharsets.UTF_8);
if (onBodyCachedListener != null) {
onBodyCachedListener.run();
}
});
return super.getBody()
.doOnNext(dataBuffer -> {
if (cachedBody == null) {
cachedBody = "";
}
cachedBody += dataBuffer.toString(StandardCharsets.UTF_8);
})
.doFinally(signalType -> {
if (signalType == SignalType.ON_COMPLETE && onBodyCachedListener != null) {
onBodyCachedListener.run();
}
});
}
}