Skip to content

Commit 72fe835

Browse files
committed
fixes #404 add test case to replicate the issue
1 parent 9d31e80 commit 72fe835

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.networknt.schema;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
import java.io.InputStream;
9+
import java.util.Set;
10+
11+
public class Issue404Test {
12+
protected JsonSchema getJsonSchemaFromStreamContentV7(InputStream schemaContent) {
13+
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
14+
return factory.getSchema(schemaContent);
15+
}
16+
17+
protected JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception {
18+
ObjectMapper mapper = new ObjectMapper();
19+
JsonNode node = mapper.readTree(content);
20+
return node;
21+
}
22+
23+
@Test
24+
public void expectObjectNotIntegerV7() throws Exception {
25+
String schemaPath = "/schema/issue404-v7.json";
26+
String dataPath = "/data/issue404.json";
27+
InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath);
28+
JsonSchema schema = getJsonSchemaFromStreamContentV7(schemaInputStream);
29+
InputStream dataInputStream = getClass().getResourceAsStream(dataPath);
30+
JsonNode node = getJsonNodeFromStreamContent(dataInputStream);
31+
Set<ValidationMessage> errors = schema.validate(node);
32+
Assert.assertEquals(0, errors.size());
33+
}
34+
35+
}

src/test/resources/data/issue404.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"bar": 1
3+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$id": "https://example.com/address.schema.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"type": "object",
5+
"properties": {
6+
"foo": {
7+
"type": "object",
8+
"enum": [1, 2, 3]
9+
},
10+
"bar": {
11+
"$ref": "#/properties/foo"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)