Skip to content

Commit 2af4fd9

Browse files
authored
Merge pull request #1 from networknt/master
Merge Pull Request
2 parents 133f8e4 + 51e18fd commit 2af4fd9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1316
-598
lines changed

CHANGELOG.md

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

1010
### Changed
1111

12+
## 1.0.38 - 2020-04-12
13+
14+
### Added
15+
16+
### Changed
17+
18+
- fixes #281 EmailValidator use ValidatorTypeCode Datetime
19+
20+
## 1.0.37 - 2020-04-06
21+
22+
### Added
23+
24+
### Changed
25+
26+
- fixes #280 NullPointerException in regex pattern validation if no SchemaValidatorsConfig is passed. Thanks @waizuwolf
27+
28+
## 1.0.36 - 2020-03-22
29+
30+
### Added
31+
32+
### Changed
33+
34+
- fixes #273 make the getInstance() deprecated
35+
- fixes #258 Cyclic dependencies result in StackOverflowError. Thanks @francesc79
36+
37+
## 1.0.35 - 2020-03-13
38+
39+
### Added
40+
41+
### Changed
42+
43+
- fixes #272 Use ECMA-262 validator when requested. Thanks @eirnym
44+
45+
## 1.0.34 - 2020-03-12
46+
47+
### Added
48+
49+
### Changed
50+
51+
- fixes #268 Collector Context changes to handle simple Objects. Thanks @prashanthjos
52+
- fixes #266 reformat the code and resolve javadoc warnnings
53+
1254
## 1.0.33 - 2020-03-09
1355

1456
### Added

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ Maven:
8080
<dependency>
8181
<groupId>com.networknt</groupId>
8282
<artifactId>json-schema-validator</artifactId>
83-
<version>1.0.33</version>
83+
<version>1.0.38</version>
8484
</dependency>
8585
```
8686

8787
Gradle:
8888

8989
```
9090
dependencies {
91-
compile(group: "com.networknt", name: "json-schema-validator", version: "1.0.33");
91+
compile(group: "com.networknt", name: "json-schema-validator", version: "1.0.38");
9292
}
9393
```
9494

@@ -112,6 +112,7 @@ For the latest version, please check the [release](https://github.com/networknt/
112112

113113
## [Collector Context](doc/collector_context.md)
114114

115+
## [ECMA-262 Regex](doc/ecma-262.md)
115116

116117
## Known issues
117118

@@ -155,7 +156,7 @@ Thanks to the following people who have contributed to this project. If you are
155156

156157
For all contributors, please visit https://github.com/networknt/json-schema-validator/graphs/contributors
157158

158-
If you are a contributor, please join the [GitHub Sponsors](https://github.com/sponsors) and swithch the link to your sponsors dashboard via a PR.
159+
If you are a contributor, please join the [GitHub Sponsors](https://github.com/sponsors) and switch the link to your sponsors dashboard via a PR.
159160

160161
## Sponsors
161162

doc/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ When typeLoose is true, the validator will convert strings to different types to
2626

2727
* failFast
2828

29-
When set to true, the validation process stops immediately when the first error occurs. This mostly used on microservices that is designed to [fail-fast](https://www.networknt.com/architecture/fail-fast/), or users don't want to see hundreds of errors for a big payload. Please be aware that the validator throws an exception in the case the first error occurs. To learn how to use it, please follow the [test case](https://github.com/networknt/json-schema-validator/blob/master/src/test/java/com/networknt/schema/JsonSchemaTest.java#L352).
29+
When set to true, the validation process stops immediately when the first error occurs. This mostly used on microservices that is designed to [fail-fast](https://www.networknt.com/architecture/fail-fast/), or users don't want to see hundreds of errors for a big payload. Please be aware that the validator throws an exception in the case the first error occurs. To learn how to use it, please follow the [test case](https://github.com/networknt/json-schema-validator/blob/master/src/test/java/com/networknt/schema/V4JsonSchemaTest.java#L352).
3030

3131
* handleNullableField
3232

doc/ecma-262.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
For the pattern validator, we now have two options for regex in the library. The default one is java.util. regex; however, you can use the ECMA-262 standard library org.jruby.joni by configuration.
2+
3+
As we know, the JSON schema is designed based on the Javascript language and its regex. The Java internal implementation has some differences which don't comply with the standard. For most users, these edge cases are not the issue as they are not using them anyway. Even when they are using it, they are expecting the Java regex result as the application is built on the Java platform. For users who want to ensure that they are using 100% standard patter validator, we have provided an option to override the default regex library with org.jruby.joni that is complying with the ECMA-262 standard.
4+
5+
### Which one to choose?
6+
7+
If you want a faster regex lib and don't care about the slight difference between Java and Javascript regex, then you don't need to do anything. The default regex lib is the java.util.regex.
8+
9+
If you want to ensure full compliance, use the org.jruby.joni. It is 1.5 times slower then java.util.regex. Depending on your use case, it might not be an issue.
10+
11+
### How to switch?
12+
13+
Here is the test case that shows how to pass a config object to use the ECMA-262 library.
14+
15+
```
16+
@Test(expected = JsonSchemaException.class)
17+
public void testInvalidPatternPropertiesValidatorECMA262() throws Exception {
18+
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
19+
config.setEcma262Validator(true);
20+
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
21+
JsonSchema schema = factory.getSchema("{\"patternProperties\":6}", config);
22+
23+
JsonNode node = getJsonNodeFromStringContent("");
24+
Set<ValidationMessage> errors = schema.validate(node);
25+
Assert.assertEquals(errors.size(), 0);
26+
}
27+
```
28+
29+

doc/schema-map.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ Basically, you can specify a mapping in the builder. For more details, please ta
1717
### Real Example
1818

1919
https://github.com/JMRI/JMRI/blob/master/java/src/jmri/server/json/schema-map.json
20+
21+
In case you provide the schema through an InputStream or a String to resolve $ref with URN (relative path), you need to provide the URNFactory to the JsonSchemaFactory.Builder.
22+
URNFactory interface will allow you to resolve URN to URI.
23+
24+
please take a look at the test cases and the [PR](https://github.com/networknt/json-schema-validator/pull/274).

doc/validators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ The `if`, `then` and `else` keywords allow the application of a subschema based
1111

1212
If `if` is valid, `then` must also be valid (and `else` is ignored.) If `if` is invalid, `else` must also be valid (and `then` is ignored).
1313

14-
For usage, please refer to the test cases at https://github.com/networknt/json-schema-validator/blob/master/src/test/resources/tests/if.json
14+
For usage, please refer to the test cases at https://github.com/networknt/json-schema-validator/blob/master/src/test/resources/draft7/if-then-else.json
1515

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<modelVersion>4.0.0</modelVersion>
2121
<groupId>com.networknt</groupId>
2222
<artifactId>json-schema-validator</artifactId>
23-
<version>1.0.33</version>
23+
<version>1.0.38</version>
2424
<packaging>bundle</packaging>
2525
<description>A json schema validator that supports draft v4, v6, v7 and v2019-09</description>
2626
<url>https://github.com/networknt/json-schema-validator</url>
@@ -65,11 +65,12 @@
6565
<version.jackson>2.10.0</version.jackson>
6666
<version.slf4j>1.7.25</version.slf4j>
6767
<version.common-lang3>3.5</version.common-lang3>
68+
<version.joni>2.1.31</version.joni>
6869
<version.logback>1.2.3</version.logback>
6970
<version.junit>4.12</version.junit>
7071
<version.mockito>2.7.21</version.mockito>
7172
<version.hamcrest>1.3</version.hamcrest>
72-
<version.undertow>2.0.28.Final</version.undertow>
73+
<version.undertow>2.0.29.Final</version.undertow>
7374
</properties>
7475
<dependencies>
7576
<dependency>
@@ -87,6 +88,11 @@
8788
<artifactId>commons-lang3</artifactId>
8889
<version>${version.common-lang3}</version>
8990
</dependency>
91+
<dependency>
92+
<groupId>org.jruby.joni</groupId>
93+
<artifactId>joni</artifactId>
94+
<version>${version.joni}</version>
95+
</dependency>
9096
<dependency>
9197
<groupId>ch.qos.logback</groupId>
9298
<artifactId>logback-classic</artifactId>
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
/*
2+
* Copyright (c) 2020 Network New Technologies Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.networknt.schema;
217

3-
public abstract class AbstractCollector<E> implements Collector<E>{
18+
public abstract class AbstractCollector<E> implements Collector<E> {
419

5-
@Override
6-
public void combine(Object object) {
7-
// Do nothing. This is the default Implementation.
8-
}
20+
@Override
21+
public void combine(Object object) {
22+
// Do nothing. This is the default Implementation.
23+
}
924
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public AdditionalPropertiesValidator(String schemaPath, JsonNode schemaNode, Jso
4040
additionalPropertiesSchema = null;
4141
} else if (schemaNode.isObject()) {
4242
allowAdditionalProperties = true;
43-
additionalPropertiesSchema = new JsonSchema(validationContext, getValidatorType().getValue(), parentSchema.getCurrentUri(), schemaNode, parentSchema);
43+
additionalPropertiesSchema = new JsonSchema(validationContext, getValidatorType().getValue(), parentSchema.getCurrentUri(), schemaNode, parentSchema)
44+
.initialize();
4445
} else {
4546
allowAdditionalProperties = false;
4647
additionalPropertiesSchema = null;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public AllOfValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
3131
super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.ALL_OF, validationContext);
3232
int size = schemaNode.size();
3333
for (int i = 0; i < size; i++) {
34-
schemas.add(new JsonSchema(validationContext, getValidatorType().getValue(), parentSchema.getCurrentUri(), schemaNode.get(i), parentSchema));
34+
schemas.add(new JsonSchema(validationContext, getValidatorType().getValue(), parentSchema.getCurrentUri(), schemaNode.get(i), parentSchema)
35+
.initialize());
3536
}
3637
}
3738

0 commit comments

Comments
 (0)