diff --git a/pom.xml b/pom.xml
index 263fe34..c7263be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
4.0.0
com.mservicetech
openapi-schema-validation
- 2.0.2
+ 2.0.3
jar
openapi schema for openpai 3.*
https://github.com/mservicetech/openapi-schema-validation
diff --git a/src/main/java/com/mservicetech/openapi/common/RequestEntity.java b/src/main/java/com/mservicetech/openapi/common/RequestEntity.java
index b04520b..c8b8302 100644
--- a/src/main/java/com/mservicetech/openapi/common/RequestEntity.java
+++ b/src/main/java/com/mservicetech/openapi/common/RequestEntity.java
@@ -3,6 +3,8 @@
import java.util.HashMap;
import java.util.Map;
+import com.fasterxml.jackson.databind.JsonNode;
+
public class RequestEntity {
Map pathParameters;
@@ -53,6 +55,10 @@ public void setRequestBody(String requestBody) {
this.requestBody = requestBody;
}
+ public void setRequestBody(JsonNode requestBody) {
+ this.requestBody = requestBody.toPrettyString();
+ }
+
public String getContentType() {
return contentType;
}
diff --git a/src/test/java/com/mservicetech/openapi/validation/OpenApiValidatorTest.java b/src/test/java/com/mservicetech/openapi/validation/OpenApiValidatorTest.java
index 6d6913c..4387357 100644
--- a/src/test/java/com/mservicetech/openapi/validation/OpenApiValidatorTest.java
+++ b/src/test/java/com/mservicetech/openapi/validation/OpenApiValidatorTest.java
@@ -1,5 +1,8 @@
package com.mservicetech.openapi.validation;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.mservicetech.openapi.common.RequestEntity;
import com.mservicetech.openapi.common.Status;
@@ -81,6 +84,21 @@ public void testRequestBody3() {
//{"statusCode":400,"code":"ERR11004","message":"VALIDATOR_SCHEMA","description":"Schema Validation Error - requestBody.id: string found, integer expected","severity":"ERROR"}
}
+ @Test
+ public void testRequestBody4() throws JsonProcessingException {
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream("json/req3.json");
+ String req = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
+ RequestEntity requestEntity = new RequestEntity();
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode jsonNode = mapper.readTree(req);
+ requestEntity.setRequestBody(jsonNode);
+ requestEntity.setContentType("application/json");
+ Status status = openApiValidator.validateRequestPath("/pets", "post", requestEntity);
+ Assert.assertNotNull(status);
+ Assert.assertEquals( status.getCode(), "ERR11004");
+ //{"statusCode":400,"code":"ERR11004","message":"VALIDATOR_SCHEMA","description":"Schema Validation Error - requestBody.id: string found, integer expected","severity":"ERROR"}
+ }
+
@Test
public void testRequestPath() {