File tree Expand file tree Collapse file tree 3 files changed +26
-14
lines changed
openapi-validation-core/src/main/java/com/getyourguide/openapi/validation/core
spring-boot-starter-webflux-spring2.7/src/main/java/com/getyourguide/openapi/validation/filter/decorator
spring-boot-starter-webflux/src/main/java/com/getyourguide/openapi/validation/filter/decorator Expand file tree Collapse file tree 3 files changed +26
-14
lines changed Original file line number Diff line number Diff line change @@ -83,8 +83,6 @@ private OpenApiViolation buildOpenApiViolation(
8383 private boolean isViolationExcluded (OpenApiViolation openApiViolation ) {
8484 return
8585 violationExclusions .isExcluded (openApiViolation )
86- // JSON parse errors should be ignored as it can't be compared to the schema then (this also prevents logging personal data!)
87- || openApiViolation .getMessage ().startsWith ("Unable to parse JSON" )
8886 // If it matches more than 1, then we don't want to log a validation error
8987 || openApiViolation .getMessage ().matches (
9088 ".*\\ [Path '[^']+'] Instance failed to match exactly one schema \\ (matched [1-9][0-9]* out of \\ d\\ ).*" );
Original file line number Diff line number Diff line change 1010import org .springframework .http .server .reactive .ServerHttpRequestDecorator ;
1111import org .springframework .lang .NonNull ;
1212import reactor .core .publisher .Flux ;
13+ import reactor .core .publisher .SignalType ;
1314
1415public class BodyCachingServerHttpRequestDecorator extends ServerHttpRequestDecorator {
1516 private final TrafficSelector trafficSelector ;
@@ -38,11 +39,17 @@ public Flux<DataBuffer> getBody() {
3839 return super .getBody ();
3940 }
4041
41- return super .getBody ().doOnNext (dataBuffer -> {
42- cachedBody = dataBuffer .toString (StandardCharsets .UTF_8 );
43- if (onBodyCachedListener != null ) {
44- onBodyCachedListener .run ();
45- }
46- });
42+ return super .getBody ()
43+ .doOnNext (dataBuffer -> {
44+ if (cachedBody == null ) {
45+ cachedBody = "" ;
46+ }
47+ cachedBody += dataBuffer .toString (StandardCharsets .UTF_8 );
48+ })
49+ .doFinally (signalType -> {
50+ if (signalType == SignalType .ON_COMPLETE && onBodyCachedListener != null ) {
51+ onBodyCachedListener .run ();
52+ }
53+ });
4754 }
4855}
Original file line number Diff line number Diff line change 1010import org .springframework .http .server .reactive .ServerHttpRequestDecorator ;
1111import org .springframework .lang .NonNull ;
1212import reactor .core .publisher .Flux ;
13+ import reactor .core .publisher .SignalType ;
1314
1415public class BodyCachingServerHttpRequestDecorator extends ServerHttpRequestDecorator {
1516 private final TrafficSelector trafficSelector ;
@@ -38,11 +39,17 @@ public Flux<DataBuffer> getBody() {
3839 return super .getBody ();
3940 }
4041
41- return super .getBody ().doOnNext (dataBuffer -> {
42- cachedBody = dataBuffer .toString (StandardCharsets .UTF_8 );
43- if (onBodyCachedListener != null ) {
44- onBodyCachedListener .run ();
45- }
46- });
42+ return super .getBody ()
43+ .doOnNext (dataBuffer -> {
44+ if (cachedBody == null ) {
45+ cachedBody = "" ;
46+ }
47+ cachedBody += dataBuffer .toString (StandardCharsets .UTF_8 );
48+ })
49+ .doFinally (signalType -> {
50+ if (signalType == SignalType .ON_COMPLETE && onBodyCachedListener != null ) {
51+ onBodyCachedListener .run ();
52+ }
53+ });
4754 }
4855}
You can’t perform that action at this time.
0 commit comments