File tree Expand file tree Collapse file tree
java/com/networknt/schema Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ {
2+ "firstName" : " John" ,
3+ "lastName" : " Doe" ,
4+ "age" : 21
5+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments