From c46a8042b8f9170167335db19084e7dfcb6b9de5 Mon Sep 17 00:00:00 2001 From: Patrick Boos Date: Mon, 18 Mar 2024 16:22:23 +0100 Subject: [PATCH 1/4] bugfix: undertow missing request body --- .../filter/MultiReadContentCachingRequestWrapper.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-starter/spring-boot-starter-web/src/main/java/com/getyourguide/openapi/validation/filter/MultiReadContentCachingRequestWrapper.java b/spring-boot-starter/spring-boot-starter-web/src/main/java/com/getyourguide/openapi/validation/filter/MultiReadContentCachingRequestWrapper.java index b9ba01b6..34488a2e 100644 --- a/spring-boot-starter/spring-boot-starter-web/src/main/java/com/getyourguide/openapi/validation/filter/MultiReadContentCachingRequestWrapper.java +++ b/spring-boot-starter/spring-boot-starter-web/src/main/java/com/getyourguide/openapi/validation/filter/MultiReadContentCachingRequestWrapper.java @@ -21,12 +21,12 @@ public MultiReadContentCachingRequestWrapper(HttpServletRequest request, int con @Override public ServletInputStream getInputStream() throws IOException { - var inputStream = super.getInputStream(); - if (inputStream.isFinished()) { - return new CachedServletInputStream(getContentAsByteArray()); + var cachedContent = getContentAsByteArray(); + if (cachedContent.length > 0 ) { + return new CachedServletInputStream(cachedContent); } - return inputStream; + return super.getInputStream(); } @Override From 57972bd4e529725368e2d4c3628bce6ffc4e32eb Mon Sep 17 00:00:00 2001 From: Patrick Boos Date: Mon, 18 Mar 2024 16:22:53 +0100 Subject: [PATCH 2/4] update example to reproduce problem --- examples/openapi.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/openapi.yaml b/examples/openapi.yaml index b67f9983..44a82b31 100644 --- a/examples/openapi.yaml +++ b/examples/openapi.yaml @@ -35,7 +35,7 @@ paths: description: Update index operationId: postIndex requestBody: - required: false + required: true content: application/json: schema: From 779c5d4b534537e57748d72e9748c642264f44cb Mon Sep 17 00:00:00 2001 From: Patrick Boos Date: Mon, 18 Mar 2024 16:23:10 +0100 Subject: [PATCH 3/4] add .http file to easily send requests --- examples/http/requests.http | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/http/requests.http diff --git a/examples/http/requests.http b/examples/http/requests.http new file mode 100644 index 00000000..0b18407f --- /dev/null +++ b/examples/http/requests.http @@ -0,0 +1,16 @@ +### POST request +POST http://localhost:8080/ +Content-Type: application/json + +{ + "name": 1 +} + +### GET request +GET http://localhost:8080/?fromDate=2020-01-01 + +### GET request (with body) +GET http://localhost:8080/?fromDate=2020-01-01 +Content-Type: application/json + +{} From 9e38ddd9ad5b7d4a108bcad7ea772062affbc142 Mon Sep 17 00:00:00 2001 From: Patrick Boos Date: Mon, 18 Mar 2024 16:25:35 +0100 Subject: [PATCH 4/4] formatting --- .../filter/MultiReadContentCachingRequestWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-starter/spring-boot-starter-web/src/main/java/com/getyourguide/openapi/validation/filter/MultiReadContentCachingRequestWrapper.java b/spring-boot-starter/spring-boot-starter-web/src/main/java/com/getyourguide/openapi/validation/filter/MultiReadContentCachingRequestWrapper.java index 34488a2e..850d1f9f 100644 --- a/spring-boot-starter/spring-boot-starter-web/src/main/java/com/getyourguide/openapi/validation/filter/MultiReadContentCachingRequestWrapper.java +++ b/spring-boot-starter/spring-boot-starter-web/src/main/java/com/getyourguide/openapi/validation/filter/MultiReadContentCachingRequestWrapper.java @@ -22,7 +22,7 @@ public MultiReadContentCachingRequestWrapper(HttpServletRequest request, int con @Override public ServletInputStream getInputStream() throws IOException { var cachedContent = getContentAsByteArray(); - if (cachedContent.length > 0 ) { + if (cachedContent.length > 0) { return new CachedServletInputStream(cachedContent); }