From 90d52c29b053c426070e31a1161da84cf9e4c66c Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 3 Jun 2021 16:33:54 -0700 Subject: [PATCH 1/3] test case with null body --- .../io/swagger/oas/test/integration/RequestTestIT.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java b/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java index e2c0b0ae..76965453 100644 --- a/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java +++ b/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java @@ -47,6 +47,13 @@ public class RequestTestIT { ApiClient client = new ApiClient(); + @Test + public void verifyUpdatePet() throws Exception { + String path = "/pets"; + String str = client.invokeAPI(path, "POST", new HashMap(), null, new HashMap(), null, "application/json", null, new String[0]); + assertEquals(str, "{\"street\":\"3 street\"}"); + } + @Test public void verifyValidDateTimeInput() throws Exception { String path = "/withDate/" + new DateTime().toString(); From 2933e6a5ca36f0ed07556d3b43fb9b6be9735e74 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 3 Jun 2021 16:38:30 -0700 Subject: [PATCH 2/3] updated expected response --- .../java/io/swagger/oas/test/integration/RequestTestIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java b/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java index 76965453..bc12060e 100644 --- a/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java +++ b/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java @@ -51,7 +51,7 @@ public class RequestTestIT { public void verifyUpdatePet() throws Exception { String path = "/pets"; String str = client.invokeAPI(path, "POST", new HashMap(), null, new HashMap(), null, "application/json", null, new String[0]); - assertEquals(str, "{\"street\":\"3 street\"}"); + assertEquals(str, "OK!"); } @Test From f81d791d4779cd06287e77ef5ba194ae9512b621 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 3 Jun 2021 16:38:45 -0700 Subject: [PATCH 3/3] avoid the NPE --- .../oas/inflector/controllers/OpenAPIOperationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIOperationController.java b/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIOperationController.java index 46f5348a..097aa8b0 100644 --- a/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIOperationController.java +++ b/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIOperationController.java @@ -379,7 +379,7 @@ public Response apply(ContainerRequestContext ctx) { missingParams.add(e.getError()); } - } else if (operation.getRequestBody().getRequired()) { + } else if (Boolean.TRUE.equals(operation.getRequestBody().getRequired())) { ValidationException e = new ValidationException(); e.message(new ValidationMessage() .message("The input body `" + operation.getRequestBody() + "` is required"));