File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
src/commonMain/kotlin/io/github/optimumcode/json/schema Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ public sealed class OutputCollector<T> private constructor(
9393
9494 internal abstract fun onError (error : ValidationError )
9595
96+ internal open val isFailFast: Boolean
97+ get() = false
98+
9699 /* *
97100 * A utility method that allows to call [reportErrors] method after the [block] has been executed
98101 */
@@ -117,6 +120,9 @@ public sealed class OutputCollector<T> private constructor(
117120 override val output: Nothing
118121 get() = throw UnsupportedOperationException (" no output in empty collector" )
119122
123+ override val isFailFast: Boolean
124+ get() = true
125+
120126 override fun updateLocation (path : JsonPointer ): OutputCollector <Nothing > = this
121127
122128 override fun updateKeywordLocation (
@@ -193,6 +199,8 @@ public sealed class OutputCollector<T> private constructor(
193199 ) : OutputCollector<ValidationOutput.Flag>(parent, transformer) {
194200 private var valid: Boolean = true
195201 private var hasErrors: Boolean = false
202+ override val isFailFast: Boolean
203+ get() = true
196204 override val output: ValidationOutput .Flag
197205 get() =
198206 if (valid) {
Original file line number Diff line number Diff line change @@ -24,9 +24,13 @@ internal class JsonSchemaRoot(
2424 var result = true
2525 context.pushSchemaPath(schemaPath, scopeId)
2626 errorCollector.updateKeywordLocation(schemaPath).use {
27+ val failFast = isFailFast
2728 assertions.forEach {
2829 val valid = it.validate(element, context, this )
2930 result = result and valid
31+ if (! result && failFast) {
32+ return @use
33+ }
3034 }
3135 }
3236 context.popSchemaPath()
You can’t perform that action at this time.
0 commit comments