|
4 | 4 | import com.networknt.schema.BaseJsonSchemaValidatorTest; |
5 | 5 | import com.networknt.schema.Error; |
6 | 6 | import com.networknt.schema.InputFormat; |
| 7 | +import com.networknt.schema.OutputFormat; |
7 | 8 | import com.networknt.schema.Result; |
8 | 9 | import com.networknt.schema.Schema; |
9 | 10 | import com.networknt.schema.SchemaRegistry; |
@@ -120,4 +121,26 @@ public void onWalkEnd(WalkEvent walkEvent, List<Error> errors) { |
120 | 121 | assertEquals("#/additionalProperties/type", errors.get(1).getSchemaLocation().toString()); |
121 | 122 | assertEquals("type", errors.get(1).getKeyword()); |
122 | 123 | } |
| 124 | + |
| 125 | + @Test |
| 126 | + void shouldNotProcessIfNotObject() { |
| 127 | + SchemaRegistry schemaRegistry = SchemaRegistry.withDialect(Dialects.getDraft202012()); |
| 128 | + String schemaData = "{\n" |
| 129 | + + " \"properties\": {\n" |
| 130 | + + " \"productId\": {\n" |
| 131 | + + " \"type\": \"integer\",\n" |
| 132 | + + " \"minimum\": 1\n" |
| 133 | + + " }\n" |
| 134 | + + " },\n" |
| 135 | + + " \"additionalProperties\": {\n" |
| 136 | + + " \"type\": \"integer\"\n" |
| 137 | + + " },\n" |
| 138 | + + " \"unevaluatedProperties\": false\n" |
| 139 | + + "}"; |
| 140 | + String instanceData = "\"hello\""; |
| 141 | + Schema schema = schemaRegistry.getSchema(schemaData, InputFormat.JSON); |
| 142 | + Result result = schema.validate(instanceData, InputFormat.JSON, OutputFormat.RESULT); |
| 143 | + assertEquals(true, result.getErrors().isEmpty()); |
| 144 | + assertEquals(0, result.getExecutionContext().getAnnotations().asMap().size()); |
| 145 | + } |
123 | 146 | } |
0 commit comments