Skip to content

Commit

Permalink
creating classpath-based test for verifying that $refs work
Browse files Browse the repository at this point in the history
  • Loading branch information
erosb committed Oct 15, 2023
1 parent 215f206 commit 263b19a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 46 deletions.
12 changes: 12 additions & 0 deletions src/test/kotlin/com/github/erosb/jsonsKema/ClasspathTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())())
}
}
46 changes: 0 additions & 46 deletions src/test/kotlin/com/github/erosb/jsonsKema/RefResolutionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
19 changes: 19 additions & 0 deletions src/test/resources/classpath-base/subdir/Issue.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
17 changes: 17 additions & 0 deletions src/test/resources/classpath-base/subdir/Project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "object",
"properties": {
"name": {
"$ref": "primitives.json#identifier"
},
"issues": {
"type": "array",
"items": {
"$ref": "Issue.json"
}
},
"issueCount": {
"$ref": "primitives.json#count"
}
}
}
14 changes: 14 additions & 0 deletions src/test/resources/classpath-base/subdir/primitives.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$defs": {
"count": {
"$id": "#count",
"type": "integer",
"minimum": 0
},
"identifier": {
"$id": "#identifier",
"type": "string",
"minLength": 3
}
}
}

0 comments on commit 263b19a

Please sign in to comment.