File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
java/com/networknt/schema Expand file tree Collapse file tree 3 files changed +52
-0
lines changed 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 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
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "bar" : 1
3
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments