Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ public PropertiesValidator(SchemaLocation schemaLocation, JsonNode schemaNode, S
@Override
public void validate(ExecutionContext executionContext, JsonNode node, JsonNode rootNode,
NodePath instanceLocation) {
if (!node.isObject()) {
// ignore if not object
return;
}
validate(executionContext, node, rootNode, instanceLocation, false);
}

protected void validate(ExecutionContext executionContext, JsonNode node, JsonNode rootNode,
NodePath instanceLocation, boolean walk) {
Set<String> matchedInstancePropertyNames = null;
boolean collectAnnotations = hasUnevaluatedPropertiesInEvaluationPath(executionContext) || collectAnnotations(executionContext);
boolean collectAnnotations = hasUnevaluatedPropertiesInEvaluationPath(executionContext) || collectAnnotations(executionContext);
for (Entry<String, Schema> entry : this.schemas.entrySet()) {
JsonNode propertyNode = node.get(entry.getKey());
if (propertyNode != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.networknt.schema.BaseJsonSchemaValidatorTest;
import com.networknt.schema.Error;
import com.networknt.schema.InputFormat;
import com.networknt.schema.OutputFormat;
import com.networknt.schema.Result;
import com.networknt.schema.Schema;
import com.networknt.schema.SchemaRegistry;
Expand Down Expand Up @@ -120,4 +121,26 @@ public void onWalkEnd(WalkEvent walkEvent, List<Error> errors) {
assertEquals("#/additionalProperties/type", errors.get(1).getSchemaLocation().toString());
assertEquals("type", errors.get(1).getKeyword());
}

@Test
void shouldNotProcessIfNotObject() {
SchemaRegistry schemaRegistry = SchemaRegistry.withDialect(Dialects.getDraft202012());
String schemaData = "{\n"
+ " \"properties\": {\n"
+ " \"productId\": {\n"
+ " \"type\": \"integer\",\n"
+ " \"minimum\": 1\n"
+ " }\n"
+ " },\n"
+ " \"additionalProperties\": {\n"
+ " \"type\": \"integer\"\n"
+ " },\n"
+ " \"unevaluatedProperties\": false\n"
+ "}";
String instanceData = "\"hello\"";
Schema schema = schemaRegistry.getSchema(schemaData, InputFormat.JSON);
Result result = schema.validate(instanceData, InputFormat.JSON, OutputFormat.RESULT);
assertEquals(true, result.getErrors().isEmpty());
assertEquals(0, result.getExecutionContext().getAnnotations().asMap().size());
}
}