diff --git a/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java b/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java index 41d828eda..dbc2e4c04 100644 --- a/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java +++ b/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java @@ -157,6 +157,28 @@ public void circularReferencingDuringValidationIsDetected() assertTrue(true); } + /* + * Issue #112: what was called a "validation loop" in issue #102 was in fact + * not really one; it is possible to enter the same subschema using + * different paths. + * + * The real thing which must be checked for is a full schema pointer loop. + */ + @Test + public void enteringSamePointerWithDifferentPathsDoesNotThrowException() + throws IOException, ProcessingException + { + final JsonNode node = JsonLoader.fromResource("/other/issue112.json"); + final JsonNode schemaNode = node.get("schema"); + final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); + final JsonValidator validator = factory.getValidator(); + + final JsonNode instance = node.get("instance"); + + assertTrue(validator.validate(schemaNode, instance).isSuccess()); + assertTrue(true); + } + public static final class K1Validator extends AbstractKeywordValidator { diff --git a/src/test/resources/other/issue112.json b/src/test/resources/other/issue112.json new file mode 100644 index 000000000..232c5b123 --- /dev/null +++ b/src/test/resources/other/issue112.json @@ -0,0 +1,66 @@ +{ + "schema": + { + "$schema": "http://json-schema.org/draft-04/schema#", + + "definitions": { + "unit-value": { + "type": "object", + "properties": { + "unit": { + "type": "string" + }, + "value": { + "type": "number" + } + } + }, + "length-unit-value": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/unit-value" + }, + { + "properties": { + "unit": { + "type": "string", + "enum": [ + "cm", + "in" + ] + } + } + } + ] + }, + "something-containing-unit-value": { + "type": "object", + "properties": { + "unit-value": { + "$ref": "#/definitions/unit-value" + } + }, + "required": [ "unit-value"] + } + }, + + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/something-containing-unit-value" + }, + { + "properties": { + "unit-value": { + "$ref": "#/definitions/length-unit-value" + } + } + } + ] + }, + "instance": { + "unit": "cm", + "unit-value": { "unit": "" } + } +}