@@ -7,6 +7,7 @@ import io.github.optimumcode.json.schema.internal.DefaultReferenceResolver
7
7
import io.github.optimumcode.json.schema.internal.IsolatedLoader
8
8
import io.github.optimumcode.json.schema.internal.JsonSchemaAssertion
9
9
import io.github.optimumcode.json.schema.internal.wrapper.wrap
10
+ import io.github.optimumcode.json.schema.model.AbstractElement
10
11
import kotlinx.serialization.json.JsonElement
11
12
import kotlin.jvm.JvmOverloads
12
13
import kotlin.jvm.JvmStatic
@@ -29,10 +30,35 @@ public class JsonSchema internal constructor(
29
30
public fun validate (
30
31
value : JsonElement ,
31
32
errorCollector : ErrorCollector ,
33
+ ): Boolean = validate(value.wrap(), errorCollector)
34
+
35
+ /* *
36
+ * Validates [value] against this [JsonSchema].
37
+ * The provided [outputCollectorProvider] will be used to create [OutputCollector]
38
+ * which collects the validation result.
39
+ *
40
+ * @return validation result depending on [outputCollectorProvider]
41
+ */
42
+ public fun <T > validate (
43
+ value : JsonElement ,
44
+ outputCollectorProvider : OutputCollector .Provider <T >,
45
+ ): T = validate(value.wrap(), outputCollectorProvider)
46
+
47
+ /* *
48
+ * Validates [value] against this [JsonSchema].
49
+ * If the [value] is valid against the schema the function returns `true`.
50
+ * Otherwise, it returns `false`.
51
+ *
52
+ * All reported errors will be reported to [ErrorCollector.onError]
53
+ */
54
+ @ExperimentalApi
55
+ public fun validate (
56
+ value : AbstractElement ,
57
+ errorCollector : ErrorCollector ,
32
58
): Boolean {
33
59
val context = DefaultAssertionContext (JsonPointer .ROOT , referenceResolver)
34
60
return DelegateOutputCollector (errorCollector).use {
35
- assertion.validate(value.wrap() , context, this )
61
+ assertion.validate(value, context, this )
36
62
}
37
63
}
38
64
@@ -43,14 +69,15 @@ public class JsonSchema internal constructor(
43
69
*
44
70
* @return validation result depending on [outputCollectorProvider]
45
71
*/
72
+ @ExperimentalApi
46
73
public fun <T > validate (
47
- value : JsonElement ,
74
+ value : AbstractElement ,
48
75
outputCollectorProvider : OutputCollector .Provider <T >,
49
76
): T {
50
77
val context = DefaultAssertionContext (JsonPointer .ROOT , referenceResolver)
51
78
val collector = outputCollectorProvider.get()
52
79
collector.use {
53
- assertion.validate(value.wrap() , context, this )
80
+ assertion.validate(value, context, this )
54
81
}
55
82
return collector.output
56
83
}
0 commit comments