Skip to content

Commit 70c482d

Browse files
authored
Merge pull request #3 from networknt/master
merging last changes
2 parents 660793d + 6245eac commit 70c482d

File tree

8 files changed

+86
-11
lines changed

8 files changed

+86
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Changed
1111

12+
## 0.1.7 - 2017-04-26
13+
### Added
14+
15+
### Changed
16+
- Fixes #25 Enable Undertow server to test remote schemas
17+
- Add test with id schema as url Thanks @eskabetxe
18+
- If schema not valid to oneOf, added all errors. Thanks @eskabetxe
19+
1220
## 0.1.6 - 2017-04-03
1321
### Added
1422

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Add the following to your `pom.xml`:
4242
<dependency>
4343
<groupId>com.networknt</groupId>
4444
<artifactId>json-schema-validator</artifactId>
45-
<version>0.1.5</version>
45+
<version>0.1.7</version>
4646
</dependency>
4747
```
4848

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<modelVersion>4.0.0</modelVersion>
2020
<groupId>com.networknt</groupId>
2121
<artifactId>json-schema-validator</artifactId>
22-
<version>0.1.6</version>
22+
<version>0.1.7</version>
2323
<description>A json schema validator that supports draft v4</description>
2424
<url>https://github.com/networknt/json-schema-validator</url>
2525
<name>JsonSchemaValidator</name>

src/main/java/com/networknt/schema/OneOfValidator.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.HashSet;
2626
import java.util.List;
2727
import java.util.Set;
28+
import java.util.stream.Collectors;
2829

2930
public class OneOfValidator extends BaseJsonValidator implements JsonValidator {
3031
private static final Logger logger = LoggerFactory.getLogger(RequiredValidator.class);
@@ -45,21 +46,33 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
4546
debug(logger, node, rootNode, at);
4647

4748
int numberOfValidSchema = 0;
48-
49+
Set<ValidationMessage> errors = new HashSet<>();
50+
4951
for (JsonSchema schema : schemas) {
50-
Set<ValidationMessage> errors = schema.validate(node, rootNode, at);
51-
if (errors == null || errors.isEmpty()) {
52+
Set<ValidationMessage> schemaErrors = schema.validate(node, rootNode, at);
53+
if (schemaErrors.isEmpty()) {
5254
numberOfValidSchema++;
55+
errors = new HashSet<>();
5356
}
57+
if(numberOfValidSchema == 0){
58+
errors.addAll(schemaErrors);
59+
}
5460
if (numberOfValidSchema > 1) {
5561
break;
5662
}
5763
}
58-
59-
Set<ValidationMessage> errors = new HashSet<ValidationMessage>();
60-
if (numberOfValidSchema != 1) {
61-
errors.add(buildValidationMessage(at, ""));
64+
65+
if (numberOfValidSchema == 0) {
66+
errors = errors.stream()
67+
.filter(msg -> !ValidatorTypeCode.ADDITIONAL_PROPERTIES
68+
.equals(ValidatorTypeCode.fromValue(msg.getType())))
69+
.collect(Collectors.toSet());
70+
}
71+
if (numberOfValidSchema > 1) {
72+
errors = new HashSet<>();
73+
errors.add(buildValidationMessage(at, ""));
6274
}
75+
6376
return errors;
6477
}
6578

src/main/java/com/networknt/schema/ValidatorTypeCode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public enum ValidatorTypeCode {
2525
"{0}.{1}: is not defined in the schema and the schema does not allow additional properties")),
2626
ALL_OF("allOf", "1002", new MessageFormat("{0}: should be valid to all the schemas {1}")),
2727
ANY_OF("anyOf", "1003", new MessageFormat("{0}: should be valid to any of the schemas {1}")),
28-
CROSS_EDITS("crossEdits", "", new MessageFormat("{0}: has an error with 'cross edits'")),
28+
CROSS_EDITS("crossEdits", "1004", new MessageFormat("{0}: has an error with 'cross edits'")),
2929
DEPENDENCIES("dependencies", "1007", new MessageFormat("{0}: has an error with dependencies {1}")),
30-
EDITS("edits", "", new MessageFormat("{0}: has an error with 'edits'")),
30+
EDITS("edits", "1005", new MessageFormat("{0}: has an error with 'edits'")),
3131
ENUM("enum", "1008", new MessageFormat("{0}: does not have a value in the enumeration {1}")),
3232
FORMAT("format", "1009", new MessageFormat("{0}: does not match the {1} pattern {2}")),
3333
ITEMS("items", "1010", new MessageFormat("{0}[{1}]: no validator found at this index")),

src/test/java/com/networknt/schema/JsonSchemaTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,10 @@ public void testTypeValidator() throws Exception {
259259
public void testUniqueItemsValidator() throws Exception {
260260
runTestFile("tests/uniqueItems.json");
261261
}
262+
263+
@Test
264+
public void testIdSchemaWithUrl() throws Exception {
265+
runTestFile("tests/id_schema/property.json");
266+
}
262267

263268
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"description": "id as schema",
4+
"schema": {
5+
"id": "http://localhost:1234/id_schema/schema/features.json",
6+
"title": "property object",
7+
"type": "object",
8+
"properties": {
9+
"featuresInteger": {
10+
"$ref": "#/featuresInteger"
11+
},
12+
"featuresBoolean": {
13+
"$ref": "#/featuresBoolean"
14+
}
15+
},
16+
"additionalProperties": false
17+
},
18+
"tests": [
19+
{
20+
"data": {
21+
"featuresInteger": 4,
22+
"featuresBoolean": true
23+
},
24+
"valid": true
25+
},
26+
{
27+
"data": {
28+
"featuresInteger": 4.0,
29+
"featuresBoolean": true
30+
},
31+
"valid": false
32+
}
33+
]
34+
}
35+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "features fields",
4+
"featuresBoolean": {
5+
"title": "boolean feature",
6+
"type": "boolean"
7+
},
8+
"featuresInteger": {
9+
"title": "integer feature",
10+
"type": "integer",
11+
"minimum": 1,
12+
"maximum": 99999
13+
}
14+
}

0 commit comments

Comments
 (0)