From 263b19afd2ac31117e59d05fdb74bb68d183c3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Er=C5=91s?= Date: Sun, 15 Oct 2023 20:12:14 +0200 Subject: [PATCH] creating classpath-based test for verifying that $refs work --- .../github/erosb/jsonsKema/ClasspathTest.kt | 12 +++++ .../erosb/jsonsKema/RefResolutionTest.kt | 46 ------------------- .../classpath-base/subdir/Issue.json | 19 ++++++++ .../classpath-base/subdir/Project.json | 17 +++++++ .../classpath-base/subdir/primitives.json | 14 ++++++ 5 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 src/test/resources/classpath-base/subdir/Issue.json create mode 100644 src/test/resources/classpath-base/subdir/Project.json create mode 100644 src/test/resources/classpath-base/subdir/primitives.json diff --git a/src/test/kotlin/com/github/erosb/jsonsKema/ClasspathTest.kt b/src/test/kotlin/com/github/erosb/jsonsKema/ClasspathTest.kt index e76f7a8..1f5f1ff 100644 --- a/src/test/kotlin/com/github/erosb/jsonsKema/ClasspathTest.kt +++ b/src/test/kotlin/com/github/erosb/jsonsKema/ClasspathTest.kt @@ -18,4 +18,16 @@ class ClasspathTest { assertEquals(2, actual!!.causes.size) } + + @Test + fun `an other test with subschemas referring to each other`() { + val loader = SchemaLoader.forURL("classpath://classpath-base/subdir/Project.json") + val sch = loader.load() + val actual = Validator.forSchema(sch).validate(JsonParser(""" + { + "prop1": "bogus", + "prop2": "values" + } + """.trimIndent())()) + } } diff --git a/src/test/kotlin/com/github/erosb/jsonsKema/RefResolutionTest.kt b/src/test/kotlin/com/github/erosb/jsonsKema/RefResolutionTest.kt index 4835e7a..6f4cb42 100644 --- a/src/test/kotlin/com/github/erosb/jsonsKema/RefResolutionTest.kt +++ b/src/test/kotlin/com/github/erosb/jsonsKema/RefResolutionTest.kt @@ -551,50 +551,4 @@ class RefResolutionTest { ) )() as CompositeSchema } - - @Test - fun `more references within a non-root document`() { - val actual = createSchemaLoaderForString( - """ - { - "$ref": "mem://main.json#/$defs/A" - } - """, - mapOf( - Pair( - "mem://main.json", - """ - { - "$defs": { - "A": { - "title": "A", - "$ref": "#/$defs/B" - }, - "B": { - "title": "B", - "type": "object", - "properties": { - "count": { - "$ref": "primitives.json#/$defs/count" - } - } - } - } - } - """ - ), - Pair("mem://primitives.json", - """ - { - "$defs": { - "count": { - "type": "integer", - "minimum": 0 - } - } - } - """.trimIndent()) - ) - )() as CompositeSchema - } } diff --git a/src/test/resources/classpath-base/subdir/Issue.json b/src/test/resources/classpath-base/subdir/Issue.json new file mode 100644 index 0000000..c13eff6 --- /dev/null +++ b/src/test/resources/classpath-base/subdir/Issue.json @@ -0,0 +1,19 @@ +{ + "type": "object", + "additionalProperties": false, + "properties": { + "title": { + "$ref": "primitives.json#identifier" + }, + "labels": { + "$ref": "#/$defs/Labels" + } + }, + "$defs": { + "Labels": { + "additionalProperties": { + "$ref": "primitives.json#identifier" + } + } + } +} diff --git a/src/test/resources/classpath-base/subdir/Project.json b/src/test/resources/classpath-base/subdir/Project.json new file mode 100644 index 0000000..b4f43f8 --- /dev/null +++ b/src/test/resources/classpath-base/subdir/Project.json @@ -0,0 +1,17 @@ +{ + "type": "object", + "properties": { + "name": { + "$ref": "primitives.json#identifier" + }, + "issues": { + "type": "array", + "items": { + "$ref": "Issue.json" + } + }, + "issueCount": { + "$ref": "primitives.json#count" + } + } +} diff --git a/src/test/resources/classpath-base/subdir/primitives.json b/src/test/resources/classpath-base/subdir/primitives.json new file mode 100644 index 0000000..b11b787 --- /dev/null +++ b/src/test/resources/classpath-base/subdir/primitives.json @@ -0,0 +1,14 @@ +{ + "$defs": { + "count": { + "$id": "#count", + "type": "integer", + "minimum": 0 + }, + "identifier": { + "$id": "#identifier", + "type": "string", + "minLength": 3 + } + } +}