From 200b7efeae080c67d5dc81f3980fbe98c1b08a76 Mon Sep 17 00:00:00 2001 From: Onno Bleyenga Date: Mon, 1 Mar 2021 16:52:18 +0100 Subject: [PATCH] Skip validation of coordinates arrays --- pom.xml | 2 +- .../networknt/schema/PropertiesValidator.java | 4 ++ .../networknt/schema/V4JsonSchemaTest.java | 5 ++ .../resources/draft4/excluded_properties.json | 55 +++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/draft4/excluded_properties.json diff --git a/pom.xml b/pom.xml index bb6193173..710aa2968 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 4.0.0 com.networknt json-schema-validator - 1.0.44.6-GEODAN + 1.0.44.6 bundle A json schema validator that supports draft v4, v6, v7 and v2019-09 https://github.com/geodan/json-schema-validator diff --git a/src/main/java/com/networknt/schema/PropertiesValidator.java b/src/main/java/com/networknt/schema/PropertiesValidator.java index 7041702b3..4d0915103 100644 --- a/src/main/java/com/networknt/schema/PropertiesValidator.java +++ b/src/main/java/com/networknt/schema/PropertiesValidator.java @@ -37,6 +37,10 @@ public PropertiesValidator(String schemaPath, JsonNode schemaNode, JsonSchema pa schemas = new HashMap(); for (Iterator it = schemaNode.fieldNames(); it.hasNext(); ) { String pname = it.next(); + if ("coordinates".equals(pname)) { + // Quick fix to skip coordinates arrays + continue; + } schemas.put(pname, new JsonSchema(validationContext, schemaPath + "/" + pname, parentSchema.getCurrentUri(), schemaNode.get(pname), parentSchema) .initialize()); } diff --git a/src/test/java/com/networknt/schema/V4JsonSchemaTest.java b/src/test/java/com/networknt/schema/V4JsonSchemaTest.java index fb0827331..987175d03 100644 --- a/src/test/java/com/networknt/schema/V4JsonSchemaTest.java +++ b/src/test/java/com/networknt/schema/V4JsonSchemaTest.java @@ -253,6 +253,11 @@ public void testOneOfValidator() throws Exception { runTestFile("draft4/oneOf.json"); } + @Test + public void testExcludedPropertiesValidator() throws Exception { + runTestFile("draft4/excluded_properties.json"); + } + @Test public void testPatternValidator() throws Exception { runTestFile("draft4/pattern.json"); diff --git a/src/test/resources/draft4/excluded_properties.json b/src/test/resources/draft4/excluded_properties.json new file mode 100644 index 000000000..258c7f1be --- /dev/null +++ b/src/test/resources/draft4/excluded_properties.json @@ -0,0 +1,55 @@ +[ + { + "description": "Test modification in PropertiesValidator.java to skip 'coordinates' arrays", + "schema": { + "properties": { + "geometrie": { + "$ref": "#/LineString" + }, + "bar": { + "type": "string" + } + }, + "Point3D": { + "type": "array", + "description": "Point in 3D space", + "minItems": 2, + "maxItems": 3, + "items": { + "type": "number" + } + }, + "LineString": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "LineString" + ] + }, + "coordinates": { + "type": "array", + "items": { + "$ref": "#/Point3D" + } + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "Property 'coordinates' should not be validated", + "data": { + "geometrie": { + "type": "LineString", + "coordinates": [[1, 1], ["xxx"], [3, 3]] + }, + "bar": "test" + }, + "valid": true + } + ] + } +]