Skip to content

Commit 236967a

Browse files
committed
fixes #327 Unknown MetaSchema cannot be reproduced
1 parent dddd660 commit 236967a

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 Issue327Test {
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 shouldWorkV7() throws Exception {
25+
String schemaPath = "/schema/issue327-v7.json";
26+
String dataPath = "/data/issue327.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+
}

src/test/resources/data/issue327.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"firstName": "John",
3+
"lastName": "Doe",
4+
"age": 21
5+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$id": "https://example.com/person.schema.json",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "Person",
5+
"type": "object",
6+
"properties": {
7+
"firstName": {
8+
"type": "string",
9+
"description": "The person's first name."
10+
},
11+
"lastName": {
12+
"type": "string",
13+
"description": "The person's last name."
14+
},
15+
"age": {
16+
"description": "Age in years which must be equal to or greater than zero.",
17+
"type": "integer",
18+
"minimum": 0
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)