-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 606: Handle matched state in AnyOfValidator (#607)
- Loading branch information
Showing
4 changed files
with
122 additions
and
3 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,34 @@ | ||
package com.networknt.schema; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.InputStream; | ||
import java.util.Set; | ||
|
||
public class Issue606Test { | ||
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 shouldWorkV7() throws Exception { | ||
String schemaPath = "/schema/issue606-v7.json"; | ||
String dataPath = "/data/issue606.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); | ||
Assertions.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,8 @@ | ||
{ | ||
"V": [ | ||
{ | ||
"A": "foo", | ||
"B": "bar" | ||
} | ||
] | ||
} |
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,73 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"V": { | ||
"type": "array", | ||
"items": { | ||
"oneOf": [ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"X": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"X" | ||
], | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"A": { | ||
"type": "string" | ||
}, | ||
"B": { | ||
"type": "string" | ||
}, | ||
"C": { | ||
"type": "string" | ||
} | ||
}, | ||
"anyOf": [ | ||
{ | ||
"properties": { | ||
"origin": { | ||
"const": "not-present" | ||
} | ||
}, | ||
"required": [ | ||
"A", | ||
"C" | ||
] | ||
}, | ||
{ | ||
"properties": { | ||
"origin": { | ||
"const": "not-present-either" | ||
} | ||
}, | ||
"required": [ | ||
"A", | ||
"B" | ||
] | ||
} | ||
], | ||
"additionalProperties": false, | ||
"required": [ | ||
"A" | ||
], | ||
"not": { | ||
"type": "object", | ||
"required": [ | ||
"X" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |