Skip to content

Commit 200d9e9

Browse files
fduttonFaron Dutton
andauthored
Reverts Undertow version to 2.2.25.Final (#819)
* Reverts Undertow version to 2.2.25.Final Resolves #818 * Corrects walk behavior in NotValidator (#820) Resolves #484 Co-authored-by: Faron Dutton <[email protected]> * Corrects source of MPE (#821) Resolves #604 Co-authored-by: Faron Dutton <[email protected]> * Adds a unit-test for issue #590 even though this issue appears to be fixed. (#822) Resolves #590 Co-authored-by: Faron Dutton <[email protected]> --------- Co-authored-by: Faron Dutton <[email protected]>
1 parent 20ec058 commit 200d9e9

File tree

5 files changed

+112
-21
lines changed

5 files changed

+112
-21
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<version.logback>1.2.11</version.logback>
8080
<version.slf4j>2.0.7</version.slf4j>
8181
<version.surefire>3.0.0</version.surefire>
82-
<version.undertow>2.3.6.Final</version.undertow>
82+
<version.undertow>2.2.25.Final</version.undertow>
8383
</properties>
8484

8585
<dependencies>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ public Set<ValidationMessage> walk(JsonNode node, JsonNode rootNode, String at,
6262
if (shouldValidateSchema) {
6363
return validate(node, rootNode, at);
6464
}
65-
return this.schema.walk(node, rootNode, at, shouldValidateSchema);
65+
66+
Set<ValidationMessage> errors = this.schema.walk(node, rootNode, at, shouldValidateSchema);
67+
if (errors.isEmpty()) {
68+
return Collections.singleton(buildValidationMessage(at, this.schema.toString()));
69+
}
70+
return Collections.emptySet();
6671
}
6772

6873
@Override

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import java.util.*;
2828

29-
public class PropertiesValidator extends BaseJsonValidator implements JsonValidator {
29+
public class PropertiesValidator extends BaseJsonValidator {
3030
public static final String PROPERTY = "properties";
3131
private static final Logger logger = LoggerFactory.getLogger(PropertiesValidator.class);
3232
private final Map<String, JsonSchema> schemas = new LinkedHashMap<>();
@@ -36,22 +36,23 @@ public PropertiesValidator(String schemaPath, JsonNode schemaNode, JsonSchema pa
3636
this.validationContext = validationContext;
3737
for (Iterator<String> it = schemaNode.fieldNames(); it.hasNext(); ) {
3838
String pname = it.next();
39-
schemas.put(pname, validationContext.newSchema(schemaPath + "/" + pname, schemaNode.get(pname), parentSchema));
39+
this.schemas.put(pname, validationContext.newSchema(schemaPath + "/" + pname, schemaNode.get(pname), parentSchema));
4040
}
4141
}
4242

43+
@Override
4344
public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String at) {
4445
debug(logger, node, rootNode, at);
4546
CollectorContext collectorContext = CollectorContext.getInstance();
4647

4748
WalkListenerRunner propertyWalkListenerRunner = new DefaultPropertyWalkListenerRunner(this.validationContext.getConfig().getPropertyWalkListeners());
4849

49-
Set<ValidationMessage> errors = new LinkedHashSet<ValidationMessage>();
50+
Set<ValidationMessage> errors = new LinkedHashSet<>();
5051

5152
// get the Validator state object storing validation data
5253
ValidatorState state = (ValidatorState) collectorContext.get(ValidatorState.VALIDATOR_STATE_KEY);
5354

54-
for (Map.Entry<String, JsonSchema> entry : schemas.entrySet()) {
55+
for (Map.Entry<String, JsonSchema> entry : this.schemas.entrySet()) {
5556
JsonSchema propertySchema = entry.getValue();
5657
JsonNode propertyNode = node.get(entry.getKey());
5758
if (propertyNode != null) {
@@ -90,9 +91,8 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
9091
// this was a complex validator (ex oneOf) and the node has not been matched
9192
state.setMatchedNode(false);
9293
return Collections.emptySet();
93-
} else {
94-
errors.addAll(requiredErrors);
9594
}
95+
errors.addAll(requiredErrors);
9696
}
9797
}
9898
}
@@ -103,38 +103,38 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
103103

104104
@Override
105105
public Set<ValidationMessage> walk(JsonNode node, JsonNode rootNode, String at, boolean shouldValidateSchema) {
106-
HashSet<ValidationMessage> validationMessages = new LinkedHashSet<ValidationMessage>();
107-
if (applyDefaultsStrategy.shouldApplyPropertyDefaults() && node.getNodeType() == JsonNodeType.OBJECT) {
106+
HashSet<ValidationMessage> validationMessages = new LinkedHashSet<>();
107+
if (this.applyDefaultsStrategy.shouldApplyPropertyDefaults() && null != node && node.getNodeType() == JsonNodeType.OBJECT) {
108108
applyPropertyDefaults((ObjectNode) node);
109109
}
110110
if (shouldValidateSchema) {
111111
validationMessages.addAll(validate(node, rootNode, at));
112112
} else {
113113
WalkListenerRunner propertyWalkListenerRunner = new DefaultPropertyWalkListenerRunner(this.validationContext.getConfig().getPropertyWalkListeners());
114-
for (Map.Entry<String, JsonSchema> entry : schemas.entrySet()) {
114+
for (Map.Entry<String, JsonSchema> entry : this.schemas.entrySet()) {
115115
walkSchema(entry, node, rootNode, at, shouldValidateSchema, validationMessages, propertyWalkListenerRunner);
116116
}
117117
}
118118
return validationMessages;
119119
}
120120

121121
private void applyPropertyDefaults(ObjectNode node) {
122-
for (Map.Entry<String, JsonSchema> entry : schemas.entrySet()) {
122+
for (Map.Entry<String, JsonSchema> entry : this.schemas.entrySet()) {
123123
JsonNode propertyNode = node.get(entry.getKey());
124124

125125
JsonNode defaultNode = getDefaultNode(entry);
126126
if (defaultNode == null) {
127127
continue;
128128
}
129129
boolean applyDefault = propertyNode == null
130-
|| (propertyNode.isNull() && applyDefaultsStrategy.shouldApplyPropertyDefaultsIfNull());
130+
|| (propertyNode.isNull() && this.applyDefaultsStrategy.shouldApplyPropertyDefaultsIfNull());
131131
if (applyDefault) {
132132
node.set(entry.getKey(), defaultNode);
133133
}
134134
}
135135
}
136136

137-
private JsonNode getDefaultNode(final Map.Entry<String, JsonSchema> entry) {
137+
private static JsonNode getDefaultNode(final Map.Entry<String, JsonSchema> entry) {
138138
JsonSchema propertySchema = entry.getValue();
139139
return propertySchema.getSchemaNode().get("default");
140140
}
@@ -145,25 +145,25 @@ private void walkSchema(Map.Entry<String, JsonSchema> entry, JsonNode node, Json
145145
JsonNode propertyNode = (node == null ? null : node.get(entry.getKey()));
146146
boolean executeWalk = propertyWalkListenerRunner.runPreWalkListeners(ValidatorTypeCode.PROPERTIES.getValue(),
147147
propertyNode, rootNode, atPath(at, entry.getKey()), propertySchema.getSchemaPath(),
148-
propertySchema.getSchemaNode(), propertySchema.getParentSchema(), validationContext,
149-
validationContext.getJsonSchemaFactory());
148+
propertySchema.getSchemaNode(), propertySchema.getParentSchema(), this.validationContext,
149+
this.validationContext.getJsonSchemaFactory());
150150
if (executeWalk) {
151151
validationMessages.addAll(
152152
propertySchema.walk(propertyNode, rootNode, atPath(at, entry.getKey()), shouldValidateSchema));
153153
}
154154
propertyWalkListenerRunner.runPostWalkListeners(ValidatorTypeCode.PROPERTIES.getValue(), propertyNode, rootNode,
155155
atPath(at, entry.getKey()), propertySchema.getSchemaPath(), propertySchema.getSchemaNode(),
156-
propertySchema.getParentSchema(), validationContext, validationContext.getJsonSchemaFactory(), validationMessages);
156+
propertySchema.getParentSchema(), this.validationContext, this.validationContext.getJsonSchemaFactory(), validationMessages);
157157

158158
}
159159

160160
public Map<String, JsonSchema> getSchemas() {
161-
return schemas;
161+
return this.schemas;
162162
}
163163

164164

165165
@Override
166166
public void preloadJsonSchema() {
167-
preloadJsonSchemas(schemas.values());
167+
preloadJsonSchemas(this.schemas.values());
168168
}
169169
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.networknt.schema;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import org.junit.jupiter.api.Disabled;
54
import org.junit.jupiter.api.Test;
65

76
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
87

98
public class Issue604Test {
109
@Test
11-
@Disabled("This test is disabled until the issue is fixed")
1210
public void failure() {
1311
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
1412
config.setApplyDefaultsStrategy(new ApplyDefaultsStrategy(true, false, false));
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[
2+
{
3+
"description": "issue590",
4+
"schema": {
5+
"$schema": "http://json-schema.org/draft-07/schema#",
6+
"type": "object",
7+
"required": [
8+
"id"
9+
],
10+
"properties": {
11+
"id": {
12+
"type": "string"
13+
},
14+
"attributes": {
15+
"type": "object",
16+
"properties": {
17+
"createdAt": {
18+
"type": "string",
19+
"format": "date-time"
20+
},
21+
"disabled": {
22+
"type": "boolean"
23+
},
24+
"email": {
25+
"type": "string"
26+
},
27+
"handle": {
28+
"type": "string"
29+
},
30+
"icon": {
31+
"type": "string"
32+
},
33+
"modifiedAt": {
34+
"type": "string",
35+
"format": "date-time"
36+
},
37+
"name": {
38+
"type": "string"
39+
},
40+
"serviceAccount": {
41+
"type": "boolean"
42+
},
43+
"status": {
44+
"type": "string"
45+
},
46+
"title": {
47+
"type": "string"
48+
},
49+
"verified": {
50+
"type": "boolean"
51+
}
52+
}
53+
},
54+
"relationships": {
55+
"type": "object",
56+
"properties": {
57+
"org": {
58+
"type": "object",
59+
"required": [
60+
"data"
61+
],
62+
"properties": {
63+
"data": {
64+
"type": "object",
65+
"required": [
66+
"id"
67+
],
68+
"properties": {
69+
"id": {
70+
"type": "string"
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
},
80+
"tests": [
81+
{
82+
"description": "should parse",
83+
"data": { "id": "an id" },
84+
"valid": true
85+
}
86+
]
87+
}
88+
]

0 commit comments

Comments
 (0)