Skip to content

Commit de4cbb0

Browse files
committed
initial fix with integ test for #265
1 parent d3ec64e commit de4cbb0

File tree

7 files changed

+93
-0
lines changed

7 files changed

+93
-0
lines changed

core/src/main/java/org/everit/json/schema/loader/LoadingState.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ static URI extractChildId(URI parentScopeId, Object childJson, String idKeyword)
7373
SchemaLoader.SchemaLoaderBuilder initChildLoader() {
7474
SchemaLoader.SchemaLoaderBuilder rval = SchemaLoader.builder()
7575
.schemaClient(this.config.schemaClient)
76+
.useDefaults(this.config.useDefaults)
77+
.regexpFactory(this.config.regexpFactory)
78+
.nullableSupport(this.config.nullableSupport)
7679
.formatValidators(new HashMap<>(this.config.formatValidators))
7780
.resolutionScope(id)
7881
.schemaJson(schemaJson)
7982
.rootSchemaJson(rootSchemaJson)
8083
.pointerSchemas(pointerSchemas)
8184
.pointerToCurrentObj(pointerToCurrentObj);
85+
rval.schemasByURI = this.config.schemasByURI;
8286
if (DRAFT_6.equals(specVersion())) {
8387
rval.draftV6Support();
8488
} else if (DRAFT_7.equals(specVersion())) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.everit.json.schema.loader;
2+
3+
import static org.everit.json.schema.JSONMatcher.sameJsonAs;
4+
import static org.junit.Assert.assertEquals;
5+
import static org.junit.Assert.assertThat;
6+
import static org.junit.Assert.fail;
7+
8+
import java.net.URI;
9+
import java.net.URISyntaxException;
10+
11+
import org.everit.json.schema.ResourceLoader;
12+
import org.everit.json.schema.Schema;
13+
import org.everit.json.schema.ValidationException;
14+
import org.json.JSONObject;
15+
import org.junit.Test;
16+
17+
public class ConfigurationPropagationTest {
18+
19+
private static final ResourceLoader LOADER = new ResourceLoader("/org/everit/jsonvalidator/config-propagation/");
20+
21+
@Test
22+
public void configurationPropagationTest() throws URISyntaxException {
23+
SchemaLoader loader = SchemaLoader.builder()
24+
.schemaClient(SchemaClient.classPathAwareClient())
25+
.nullableSupport(true)
26+
.useDefaults(true)
27+
.registerSchemaByURI(new URI("urn:uuid:85946d9c-b896-496c-a7ac-6835f4b59f63"), LOADER.readObj("schema-by-urn.json"))
28+
.addFormatValidator(new CustomFormatValidatorTest.EvenCharNumValidator())
29+
.schemaJson(LOADER.readObj("schema.json"))
30+
.build();
31+
Schema actual = loader.load().build();
32+
JSONObject instance = LOADER.readObj("instance.json");
33+
try {
34+
actual.validate(instance);
35+
fail("did not throw validation exception");
36+
} catch (ValidationException e) {
37+
assertThat(e.toJSON(), sameJsonAs(LOADER.readObj("expected-exception.json")));
38+
}
39+
assertEquals(42, instance.get("propWithDefault"));
40+
}
41+
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"causingExceptions": [
3+
{
4+
"causingExceptions": [],
5+
"keyword": "minLength",
6+
"message": "expected minLength: 3, actual: 1",
7+
"pointerToViolation": "#/urnRefProp",
8+
"schemaLocation": "urn:uuid:85946d9c-b896-496c-a7ac-6835f4b59f63"
9+
},
10+
{
11+
"causingExceptions": [],
12+
"keyword": "format",
13+
"message": "the length of srtring [a] is odd",
14+
"pointerToViolation": "#/urnRefProp",
15+
"schemaLocation": "urn:uuid:85946d9c-b896-496c-a7ac-6835f4b59f63"
16+
}
17+
],
18+
"message": "2 schema violations found",
19+
"pointerToViolation": "#/urnRefProp",
20+
"schemaLocation": "urn:uuid:85946d9c-b896-496c-a7ac-6835f4b59f63"
21+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"nullableProp": null,
3+
"urnRefProp": "a"
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"properties": {
3+
"nullableProp": {
4+
"type": "string",
5+
"nullable": true
6+
},
7+
"propWithDefault": {
8+
"default": 42
9+
},
10+
"urnRefProp": {
11+
"$ref": "urn:uuid:85946d9c-b896-496c-a7ac-6835f4b59f63"
12+
}
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "string",
3+
"minLength": 3,
4+
"format": "evenlength"
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$ref": "classpath:/org/everit/jsonvalidator/config-propagation/remote.json"
3+
}

0 commit comments

Comments
 (0)