• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.networknt.schema;
2 
3 import com.fasterxml.jackson.databind.JsonNode;
4 import com.fasterxml.jackson.databind.ObjectMapper;
5 import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
6 import org.hamcrest.MatcherAssert;
7 import org.hamcrest.Matchers;
8 import org.junit.jupiter.api.Test;
9 
10 import java.io.InputStream;
11 
12 class Issue668Test {
getJsonSchemaFromStreamContent(InputStream schemaContent)13     protected JsonSchema getJsonSchemaFromStreamContent(InputStream schemaContent) throws Exception {
14         JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
15         YAMLMapper mapper = new YAMLMapper();
16         JsonNode node = mapper.readTree(schemaContent);
17         return factory.getSchema(node);
18     }
19 
getJsonNodeFromStreamContent(InputStream content)20     protected JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception {
21         ObjectMapper mapper = new ObjectMapper();
22         return mapper.readTree(content);
23     }
24 
25     @Test
shouldHandleReferencesToYaml()26     void shouldHandleReferencesToYaml() throws Exception {
27         String schemaPath = "/schema/issue668.yml";
28         String dataPath = "/data/issue668.json";
29         InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath);
30         JsonSchema schema = getJsonSchemaFromStreamContent(schemaInputStream);
31         InputStream dataInputStream = getClass().getResourceAsStream(dataPath);
32         JsonNode node = getJsonNodeFromStreamContent(dataInputStream);
33         MatcherAssert.assertThat(schema.validate(node), Matchers.empty());
34     }
35 }
36