Skip to content

Commit

Permalink
Skip validation of coordinates arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
onnobgd committed Mar 1, 2021
1 parent f42c80e commit 200b7ef
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.0.44.6-GEODAN</version>
<version>1.0.44.6</version>
<packaging>bundle</packaging>
<description>A json schema validator that supports draft v4, v6, v7 and v2019-09</description>
<url>https://github.com/geodan/json-schema-validator</url>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/networknt/schema/PropertiesValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public PropertiesValidator(String schemaPath, JsonNode schemaNode, JsonSchema pa
schemas = new HashMap<String, JsonSchema>();
for (Iterator<String> 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());
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/networknt/schema/V4JsonSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
55 changes: 55 additions & 0 deletions src/test/resources/draft4/excluded_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]

0 comments on commit 200b7ef

Please sign in to comment.