Skip to content

Commit ee10d97

Browse files
committed
change type of dynamicPath in failure object from JsonPointer to DynamicPath so that it includes the root document source as well
1 parent 2cbd453 commit ee10d97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+161
-111
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.erosb</groupId>
77
<artifactId>json-sKema</artifactId>
8-
<version>0.22.0</version>
8+
<version>0.23.0-SNAPSHOT</version>
99

1010
<name>json-sKema</name>
1111
<description>JSON Schema Parser and Validator</description>

src/main/kotlin/com/github/erosb/jsonsKema/AllOf.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data class AllOfValidationFailure(
1616
override val schema: AllOfSchema,
1717
override val instance: IJsonValue,
1818
override val causes: Set<ValidationFailure>,
19-
override val dynamicPath: JsonPointer
19+
override val dynamicPath: DynamicPath
2020
) : ValidationFailure(
2121
message = "${causes.size} subschemas out of ${schema.subschemas.size} failed to validate",
2222
schema = schema,

src/main/kotlin/com/github/erosb/jsonsKema/AnyOf.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data class AnyOfValidationFailure(
1717
override val schema: AnyOfSchema,
1818
override val instance: IJsonValue,
1919
override val causes: Set<ValidationFailure>,
20-
override val dynamicPath: JsonPointer
20+
override val dynamicPath: DynamicPath
2121
) : ValidationFailure(
2222
message = "no subschema out of ${schema.subschemas.size} matched",
2323
schema = schema,

src/main/kotlin/com/github/erosb/jsonsKema/Const.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal val constLoader: KeywordLoader = { ctx -> ConstSchema(ctx.keywordValue,
99
data class ConstValidationFailure(
1010
override val schema: ConstSchema,
1111
override val instance: IJsonValue,
12-
override val dynamicPath: JsonPointer
12+
override val dynamicPath: DynamicPath
1313
) : ValidationFailure(
1414
"actual instance is not the same as expected constant value",
1515
schema,

src/main/kotlin/com/github/erosb/jsonsKema/Contains.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data class ContainsValidationFailure(
2020
override val message: String,
2121
override val schema: ContainsSchema,
2222
override val instance: IJsonArray<*>,
23-
override val dynamicPath: JsonPointer
23+
override val dynamicPath: DynamicPath
2424
) : ValidationFailure(
2525
message,
2626
schema,

src/main/kotlin/com/github/erosb/jsonsKema/DependentRequired.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ data class DependentRequiredValidationFailure(
1616
val missingKeys: Set<String>,
1717
override val schema: DependentRequiredSchema,
1818
override val instance: IJsonObj,
19-
override val dynamicPath: JsonPointer
19+
override val dynamicPath: DynamicPath
2020
) : ValidationFailure("property $presentKey is present in the object but the following properties are missing: ${missingKeys.joinToString(", ")}", schema, instance, Keyword.DEPENDENT_REQUIRED)

src/main/kotlin/com/github/erosb/jsonsKema/DependentSchemas.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data class DependentSchemasValidationFailure(
2020
override val schema: DependentSchemasSchema,
2121
override val instance: IJsonValue,
2222
val causesByProperty: Map<String, ValidationFailure>,
23-
override val dynamicPath: JsonPointer
23+
override val dynamicPath: DynamicPath
2424
) : ValidationFailure(
2525
message = "some dependent subschemas did not match",
2626
schema = schema,
Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,67 @@
11
package com.github.erosb.jsonsKema
22

3-
class DynamicPath {
3+
import java.net.URI
4+
5+
class DynamicPath() {
6+
7+
constructor(rootDocumentSource: URI, path: List<String>): this() {
8+
this.rootDocumentSource = rootDocumentSource
9+
this.path.addAll(path)
10+
}
411

512
private val path = mutableListOf<String>()
613

7-
fun <P> inSegmentPath(seg: String, cb: () -> P?): P? {
14+
internal lateinit var rootDocumentSource: URI
15+
16+
fun <P> inSegmentPath(
17+
seg: String,
18+
cb: () -> P?,
19+
): P? {
820
path.add(seg)
921
val rval = cb()
1022
path.removeLast()
1123
return rval
1224
}
1325

14-
fun <P> inSegmentPath(seg: List<String>, cb: () -> P?): P? {
26+
fun <P> inSegmentPath(
27+
seg: List<String>,
28+
cb: () -> P?,
29+
): P? {
1530
path.addAll(seg)
1631
val rval = cb()
1732
val count = seg.size
1833
for (i in 1..count) path.removeLast()
1934
return rval
2035
}
2136

37+
val pointer: JsonPointer
38+
get() = JsonPointer(path.toList())
39+
40+
fun copy() = DynamicPath(rootDocumentSource, path.toMutableList())
41+
42+
operator fun plus(keyword: Keyword): DynamicPath = plus(keyword.value)
43+
44+
operator fun plus(keyword: String): DynamicPath = DynamicPath(rootDocumentSource, path + keyword)
2245

23-
fun asPointer(): JsonPointer = JsonPointer(path.toList())
46+
override fun toString(): String = rootDocumentSource.toString() + pointer.toString()
47+
48+
override fun equals(other: Any?): Boolean {
49+
if (this === other) return true
50+
if (javaClass != other?.javaClass) return false
51+
52+
other as DynamicPath
53+
54+
if (path != other.path) return false
55+
if (rootDocumentSource != other.rootDocumentSource) return false
56+
57+
return true
58+
}
59+
60+
override fun hashCode(): Int {
61+
var result = path.hashCode()
62+
result = 31 * result + rootDocumentSource.hashCode()
63+
return result
64+
}
2465

2566

2667
}

src/main/kotlin/com/github/erosb/jsonsKema/Enum.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ internal val enumLoader: KeywordLoader = { ctx ->
1111
class EnumValidationFailure(
1212
override val schema: EnumSchema,
1313
override val instance: IJsonValue,
14-
override val dynamicPath: JsonPointer
14+
override val dynamicPath: DynamicPath
1515
) : ValidationFailure("the instance is not equal to any enum values", schema, instance, Keyword.ENUM)

src/main/kotlin/com/github/erosb/jsonsKema/ExclusiveMaximum.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ internal val exclusiveMaximumLoader: KeywordLoader = { ctx ->
1111
data class ExclusiveMaximumValidationFailure(
1212
override val schema: ExclusiveMaximumSchema,
1313
override val instance: IJsonNumber,
14-
override val dynamicPath: JsonPointer
14+
override val dynamicPath: DynamicPath
1515
) : ValidationFailure("${instance.value} is greater than or equal to maximum ${schema.maximum}", schema, instance, Keyword.EXCLUSIVE_MAXIMUM)

0 commit comments

Comments
 (0)