@@ -10,6 +10,9 @@ internal typealias OutputErrorTransformer<T> = OutputCollector<T>.(ValidationErr
10
10
11
11
private val NO_TRANSFORMATION : OutputErrorTransformer <* > = { it }
12
12
13
+ /* *
14
+ * Provides collectors' implementations defined in [draft 2020-12](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-12.4)
15
+ */
13
16
public sealed class OutputCollector <T > private constructor(
14
17
parent : OutputCollector <T >? = null ,
15
18
transformer : OutputErrorTransformer <T > = NO_TRANSFORMATION ,
@@ -46,22 +49,46 @@ public sealed class OutputCollector<T> private constructor(
46
49
}
47
50
} ? : transformer
48
51
52
+ /* *
53
+ * Sets current instance location to specified [path].
54
+ * Returns an [OutputCollector] with updated location information.
55
+ */
49
56
internal abstract fun updateLocation (path : JsonPointer ): OutputCollector <T >
50
57
58
+ /* *
59
+ * Sets current keyword location to specified [path].
60
+ * Updates absolute keyword location information to [absoluteLocation].
61
+ * If [canCollapse] is `false` that will indicate the output node cannot be collapsed
62
+ * (format might ignore this if it does not support collapsing).
63
+ */
51
64
internal abstract fun updateKeywordLocation (
52
65
path : JsonPointer ,
53
66
absoluteLocation : AbsoluteLocation ? = null,
54
67
canCollapse : Boolean = true,
55
68
): OutputCollector <T >
56
69
70
+ /* *
71
+ * Add a transformation that should be applied to a reported [ValidationError].
72
+ * The specified [transformer] will be combined with earlier specified transformations (if any were provided).
73
+ * The transformation are applied in LIFO order.
74
+ */
57
75
internal abstract fun withErrorTransformer (transformer : OutputErrorTransformer <T >): OutputCollector <T >
58
76
77
+ /* *
78
+ * Creates a child [OutputCollector] that has exactly same instance, keyword and absolute locations information.
79
+ */
59
80
internal abstract fun childCollector (): OutputCollector <T >
60
81
82
+ /* *
83
+ * Commits the collected errors. Used to allow late error commit to support applicators like `oneOf`, `anyOf` etc.
84
+ */
61
85
internal open fun reportErrors () = Unit
62
86
63
87
internal abstract fun onError (error : ValidationError )
64
88
89
+ /* *
90
+ * A utility method that allows to call [reportErrors] method after the [block] has been executed
91
+ */
65
92
internal inline fun <OUT > use (block : OutputCollector <T >.() -> OUT ): OUT =
66
93
try {
67
94
block(this )
@@ -71,6 +98,9 @@ public sealed class OutputCollector<T> private constructor(
71
98
72
99
protected fun transformError (error : ValidationError ): ValidationError ? = transformerFunc(error)
73
100
101
+ /* *
102
+ * Placeholder collector when no errors should be reported
103
+ */
74
104
internal data object Empty : OutputCollector <Nothing >() {
75
105
override val output: Nothing
76
106
get() = throw UnsupportedOperationException (" no output in empty collector" )
@@ -90,6 +120,9 @@ public sealed class OutputCollector<T> private constructor(
90
120
override fun onError (error : ValidationError ) = Unit
91
121
}
92
122
123
+ /* *
124
+ * Collector to pass all the collected errors to the provided [ErrorCollector]
125
+ */
93
126
internal class DelegateOutputCollector (
94
127
private val errorCollector : ErrorCollector ,
95
128
private val parent : DelegateOutputCollector ? = null ,
0 commit comments