diff --git a/pom.xml b/pom.xml
index af4135b..4c7eb74 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,7 +57,7 @@
11
UTF-8
1.3.3
- 2.1.34
+ 2.1.35
2.16.1
2.2
2.0.12
diff --git a/src/test/java/com/mservicetech/openapi/validation/OpenApiValidatorTest.java b/src/test/java/com/mservicetech/openapi/validation/OpenApiValidatorTest.java
index 0e937b4..2843e9b 100644
--- a/src/test/java/com/mservicetech/openapi/validation/OpenApiValidatorTest.java
+++ b/src/test/java/com/mservicetech/openapi/validation/OpenApiValidatorTest.java
@@ -9,7 +9,7 @@
import com.networknt.status.Status;
import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Before;
import org.junit.Test;
import java.io.BufferedReader;
@@ -22,10 +22,10 @@
public class OpenApiValidatorTest {
- static OpenApiValidator openApiValidator;
+ private OpenApiValidator openApiValidator;
- @BeforeClass
- public static void setUp() {
+ @Before
+ public void setUp() {
openApiValidator = new OpenApiValidator("openapi.yaml");
}
@@ -503,4 +503,20 @@ public void testResponseHeader2() {
// {"statusCode":400,"code":"ERR11004","message":"VALIDATOR_SCHEMA","description":"Schema Validation Error - $: string found, integer expected","severity":"ERROR"}
}
+
+ @Test
+ public void testOpenApi3UnevaluatedProperties() {
+ openApiValidator = new OpenApiValidator("config/openapi3-unevaluatedProperties.yaml");
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream("json/person_bad_req.json");
+ String req1 = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
+
+ RequestEntity requestEntity = new RequestEntity();
+ requestEntity.setRequestBody(req1);
+ requestEntity.setContentType("application/json");
+ Status status = openApiValidator.validateRequestPath("/pets", "post", requestEntity);
+ Assert.assertNotNull(status);
+ Assert.assertEquals(status.getDescription(), "Schema Validation Error - $: property 'invalid' is not evaluated and the schema does not allow unevaluated properties");
+ }
+
+
}
diff --git a/src/test/resources/config/openapi3-unevaluatedProperties.yaml b/src/test/resources/config/openapi3-unevaluatedProperties.yaml
new file mode 100644
index 0000000..064d117
--- /dev/null
+++ b/src/test/resources/config/openapi3-unevaluatedProperties.yaml
@@ -0,0 +1,63 @@
+openapi: 3.1.0
+info:
+ version: 1.0.0
+ title: Swagger Petstore
+paths:
+ /pets:
+ post:
+ summary: Create a pet
+ operationId: createPets
+ requestBody:
+ description: Pet to add to the store
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Person'
+ responses:
+ '201':
+ description: Null response
+components:
+
+ schemas:
+ address:
+ properties:
+ residence:
+ $ref: '#/components/schemas/residence'
+ description: Residence details where the person lives
+ city:
+ type: string
+ description: City where the person lives.
+ street:
+ type: string
+ description: street where the person lives.
+ pinCode:
+ type: number
+ description: pincode of street
+ unevaluatedProperties: false
+ residence:
+ properties:
+ flatNumber:
+ type: string
+ flatName:
+ type: string
+ landmark:
+ type: string
+ unevaluatedProperties: false
+ Person:
+ properties:
+ firstName:
+ type: string
+ description: The person's first name.
+ lastName:
+ type: string
+ description: The person's last name.
+ age:
+ description: Age in years which must be equal to or greater than zero.
+ type: integer
+ minimum: 0
+ address:
+ description: Address of the person.
+ $ref: '#/components/schemas/address'
+ unevaluatedProperties: false
+
diff --git a/src/test/resources/json/person_bad_req.json b/src/test/resources/json/person_bad_req.json
new file mode 100644
index 0000000..7dfed88
--- /dev/null
+++ b/src/test/resources/json/person_bad_req.json
@@ -0,0 +1,9 @@
+{
+ "firstName": "First Name",
+ "invalid": 18,
+ "lastName": "Last Name",
+ "address": {
+ "city": "Hyderabad",
+ "pinCode": 500025
+ }
+}
\ No newline at end of file