File tree Expand file tree Collapse file tree 4 files changed +134
-0
lines changed
main/java/com/networknt/schema
java/com/networknt/schema Expand file tree Collapse file tree 4 files changed +134
-0
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,9 @@ else if (numberOfValidSchema < 1) {
197
197
}
198
198
}
199
199
200
+ // Make sure to signal parent handlers we matched
201
+ if (errors .isEmpty ())
202
+ state .setMatchedNode (true );
200
203
201
204
// reset the ValidatorState object in the ThreadLocal
202
205
validatorState .remove ();
Original file line number Diff line number Diff line change
1
+ package com .networknt .schema ;
2
+
3
+ import java .io .InputStream ;
4
+ import java .util .Set ;
5
+
6
+ import org .junit .Assert ;
7
+ import org .junit .Test ;
8
+
9
+ import com .fasterxml .jackson .databind .JsonNode ;
10
+ import com .fasterxml .jackson .databind .ObjectMapper ;
11
+
12
+ public class Issue383Test {
13
+ protected JsonSchema getJsonSchemaFromStreamContentV7 (InputStream schemaContent ) {
14
+ JsonSchemaFactory factory = JsonSchemaFactory .getInstance (SpecVersion .VersionFlag .V7 );
15
+ return factory .getSchema (schemaContent );
16
+ }
17
+
18
+ protected JsonNode getJsonNodeFromStreamContent (InputStream content ) throws Exception {
19
+ ObjectMapper mapper = new ObjectMapper ();
20
+ JsonNode node = mapper .readTree (content );
21
+ return node ;
22
+ }
23
+
24
+ @ Test
25
+ public void nestedOneOfsShouldStillMatchV7 () throws Exception {
26
+ String schemaPath = "/schema/issue383-v7.json" ;
27
+ String dataPath = "/data/issue383.json" ;
28
+ InputStream schemaInputStream = getClass ().getResourceAsStream (schemaPath );
29
+ JsonSchema schema = getJsonSchemaFromStreamContentV7 (schemaInputStream );
30
+ InputStream dataInputStream = getClass ().getResourceAsStream (dataPath );
31
+ JsonNode node = getJsonNodeFromStreamContent (dataInputStream );
32
+ Set <ValidationMessage > errors = schema .validate (node );
33
+ Assert .assertEquals (0 , errors .size ());
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "validation" : {
3
+ "all" : [
4
+ {
5
+ "notEmpty" : {
6
+ "field" : " test"
7
+ }
8
+ }
9
+ ]
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " object" ,
3
+ "properties" : {
4
+ "validation" : {
5
+ "$ref" : " #/definitions/predicateOrNull"
6
+ }
7
+ },
8
+ "definitions" : {
9
+ "fieldRef" : {
10
+ "type" : " object" ,
11
+ "properties" : {
12
+ "field" : {
13
+ "type" : " string"
14
+ },
15
+ "set" : {
16
+ "type" : " string"
17
+ }
18
+ },
19
+ "required" : [
20
+ " field"
21
+ ]
22
+ },
23
+ "patternPredicate" : {
24
+ "type" : " object" ,
25
+ "oneOf" : [
26
+ {
27
+ "properties" : {
28
+ "notEmpty" : {
29
+ "$ref" : " #/definitions/fieldRef"
30
+ }
31
+ },
32
+ "required" : [
33
+ " notEmpty"
34
+ ]
35
+ },
36
+ {
37
+ "properties" : {
38
+ "notBlank" : {
39
+ "$ref" : " #/definitions/fieldRef"
40
+ }
41
+ },
42
+ "required" : [
43
+ " notBlank"
44
+ ]
45
+ }
46
+ ]
47
+ },
48
+ "allPredicate" : {
49
+ "type" : " object" ,
50
+ "properties" : {
51
+ "all" : {
52
+ "type" : " array" ,
53
+ "minItems" : 1 ,
54
+ "items" : {
55
+ "$ref" : " #/definitions/predicate"
56
+ }
57
+ }
58
+ },
59
+ "required" : [
60
+ " all"
61
+ ]
62
+ },
63
+ "predicate" : {
64
+ "type" : " object" ,
65
+ "oneOf" : [
66
+ {
67
+ "$ref" : " #/definitions/patternPredicate"
68
+ },
69
+ {
70
+ "$ref" : " #/definitions/allPredicate"
71
+ }
72
+ ]
73
+ },
74
+ "predicateOrNull" : {
75
+ "oneOf" : [
76
+ {
77
+ "$ref" : " #/definitions/predicate"
78
+ },
79
+ {
80
+ "type" : " null"
81
+ }
82
+ ]
83
+ }
84
+ }
85
+ }
You can’t perform that action at this time.
0 commit comments