Skip to content

Commit e05fcdd

Browse files
committed
Add test to reproduce the issue
1 parent 4a384a3 commit e05fcdd

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/commonTest/kotlin/io/github/optimumcode/json/schema/assertions/number/JsonSchemaMultipleOfValidationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class JsonSchemaMultipleOfValidationTest : FunSpec() {
176176
}
177177
}
178178

179+
// https://github.com/OptimumCode/json-schema-validator/issues/70
179180
test("BUG_70 rounding problem with some numbers because double does not behave as you expect") {
180181
val schema =
181182
JsonSchema.fromDefinition(

src/commonTest/kotlin/io/github/optimumcode/json/schema/base/JsonSchemaLoaderTest.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.github.optimumcode.json.schema.JsonSchemaLoader
99
import io.github.optimumcode.json.schema.SchemaOption
1010
import io.github.optimumcode.json.schema.ValidationError
1111
import io.kotest.assertions.assertSoftly
12+
import io.kotest.assertions.throwables.shouldNotThrowAny
1213
import io.kotest.assertions.throwables.shouldNotThrowAnyUnit
1314
import io.kotest.assertions.throwables.shouldThrow
1415
import io.kotest.assertions.withClue
@@ -303,5 +304,55 @@ class JsonSchemaLoaderTest : FunSpec() {
303304
.withCustomFormat("magic", MagicFormatValidator())
304305
}.message shouldBe "format 'magic' already registered"
305306
}
307+
308+
// https://github.com/OptimumCode/json-schema-validator/issues/87
309+
test("BUG_87 relative uri-ref in root \$id causes incorrect reference resolution for root schema") {
310+
val schema =
311+
shouldNotThrowAny {
312+
JsonSchemaLoader.create()
313+
.register(
314+
"""
315+
{
316+
"${'$'}schema": "https://json-schema.org/draft/2020-12/schema",
317+
"${'$'}id": "myproject/enums/foo",
318+
"type": "integer"
319+
}
320+
""".trimIndent(),
321+
).fromDefinition(
322+
"""
323+
{
324+
"${'$'}schema": "https://json-schema.org/draft/2020-12/schema",
325+
"${'$'}id": "myproject/data/request",
326+
"type": "object",
327+
"properties": {
328+
"foobar": {
329+
"${'$'}ref": "/myproject/enums/foo"
330+
}
331+
}
332+
}
333+
""".trimIndent(),
334+
)
335+
}
336+
337+
val errors = mutableListOf<ValidationError>()
338+
val valid =
339+
schema.validate(
340+
buildJsonObject {
341+
put("foobar", JsonPrimitive("test"))
342+
},
343+
errors::add,
344+
)
345+
assertSoftly {
346+
valid shouldBe false
347+
errors.shouldContainExactly(
348+
ValidationError(
349+
schemaPath = JsonPointer("/properties/foobar/\$ref/type"),
350+
objectPath = JsonPointer("/foobar"),
351+
message = "element is not a integer",
352+
absoluteLocation = JsonPointer("/type"),
353+
),
354+
)
355+
}
356+
}
306357
}
307358
}

0 commit comments

Comments
 (0)