forked from networknt/json-schema-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- signal nodeMatch to parent handler in OneOfValidator
- Loading branch information
1 parent
e692d47
commit 09b2b04
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.networknt.schema; | ||
|
||
import java.io.InputStream; | ||
import java.util.Set; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class Issue383Test { | ||
protected JsonSchema getJsonSchemaFromStreamContentV7(InputStream schemaContent) { | ||
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); | ||
return factory.getSchema(schemaContent); | ||
} | ||
|
||
protected JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
JsonNode node = mapper.readTree(content); | ||
return node; | ||
} | ||
|
||
@Test | ||
public void nestedOneOfsShouldStillMatchV7() throws Exception { | ||
String schemaPath = "/schema/issue383-v7.json"; | ||
String dataPath = "/data/issue383.json"; | ||
InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath); | ||
JsonSchema schema = getJsonSchemaFromStreamContentV7(schemaInputStream); | ||
InputStream dataInputStream = getClass().getResourceAsStream(dataPath); | ||
JsonNode node = getJsonNodeFromStreamContent(dataInputStream); | ||
Set<ValidationMessage> errors = schema.validate(node); | ||
Assert.assertEquals(0, errors.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"validation": { | ||
"all": [ | ||
{ | ||
"notEmpty": { | ||
"field": "test" | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"validation": { | ||
"$ref": "#/definitions/predicateOrNull" | ||
} | ||
}, | ||
"definitions": { | ||
"fieldRef": { | ||
"type": "object", | ||
"properties": { | ||
"field": { | ||
"type": "string" | ||
}, | ||
"set": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"field" | ||
] | ||
}, | ||
"patternPredicate": { | ||
"type": "object", | ||
"oneOf": [ | ||
{ | ||
"properties": { | ||
"notEmpty": { | ||
"$ref": "#/definitions/fieldRef" | ||
} | ||
}, | ||
"required": [ | ||
"notEmpty" | ||
] | ||
}, | ||
{ | ||
"properties": { | ||
"notBlank": { | ||
"$ref": "#/definitions/fieldRef" | ||
} | ||
}, | ||
"required": [ | ||
"notBlank" | ||
] | ||
} | ||
] | ||
}, | ||
"allPredicate": { | ||
"type": "object", | ||
"properties": { | ||
"all": { | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"$ref": "#/definitions/predicate" | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"all" | ||
] | ||
}, | ||
"predicate": { | ||
"type": "object", | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/patternPredicate" | ||
}, | ||
{ | ||
"$ref": "#/definitions/allPredicate" | ||
} | ||
] | ||
}, | ||
"predicateOrNull": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/predicate" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
} | ||
} | ||
} |