File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
main/java/com/networknt/schema
test/java/com/networknt/schema Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ public static JsonType getSchemaNodeType(JsonNode node) {
7575 * @return the json type
7676 */
7777 public static JsonType getValueNodeType (JsonNode node , SchemaValidatorsConfig config ) {
78+ if (node == null ) {
79+ // This returns JsonType.UNKNOWN to be consistent with the behavior when
80+ // JsonNodeType.MISSING
81+ return JsonType .UNKNOWN ;
82+ }
7883 JsonNodeType type = node .getNodeType ();
7984 switch (type ) {
8085 case OBJECT :
Original file line number Diff line number Diff line change 22
33import com .fasterxml .jackson .databind .JsonNode ;
44import com .fasterxml .jackson .databind .ObjectMapper ;
5+ import com .fasterxml .jackson .databind .node .MissingNode ;
56import com .fasterxml .jackson .databind .node .ObjectNode ;
67import com .networknt .schema .walk .JsonSchemaWalkListener ;
78import com .networknt .schema .walk .WalkEvent ;
@@ -110,6 +111,26 @@ void testWalkWithDifferentListeners() throws IOException {
110111 + "}" )));
111112 }
112113
114+ @ Test
115+ void testWalkMissingNodeWithPropertiesSchema () {
116+ String schemaContents = "{\n "
117+ + " \" type\" : \" object\" ,\n "
118+ + " \" properties\" : {\n "
119+ + " \" field\" : {\n "
120+ + " \" anyOf\" : [\n "
121+ + " {\n "
122+ + " \" type\" : \" string\" \n "
123+ + " }\n "
124+ + " ]\n "
125+ + " }\n "
126+ + " }\n "
127+ + " }" ;
128+
129+ JsonSchemaFactory factory = JsonSchemaFactory .getInstance (SpecVersion .VersionFlag .V7 );
130+ JsonSchema schema = factory .getSchema (schemaContents );
131+ schema .walk (MissingNode .getInstance (), true ).getValidationMessages ();
132+ }
133+
113134 private InputStream getSchema () {
114135 return getClass ().getClassLoader ().getResourceAsStream ("schema/walk-schema.json" );
115136 }
You can’t perform that action at this time.
0 commit comments