Skip to content

Add failFast flag in flag output to skip remaining validations after first failure #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public sealed class OutputCollector<T> private constructor(

internal abstract fun onError(error: ValidationError)

internal open val isFailFast: Boolean
get() = false

/**
* A utility method that allows to call [reportErrors] method after the [block] has been executed
*/
Expand All @@ -117,6 +120,9 @@ public sealed class OutputCollector<T> private constructor(
override val output: Nothing
get() = throw UnsupportedOperationException("no output in empty collector")

override val isFailFast: Boolean
get() = true

override fun updateLocation(path: JsonPointer): OutputCollector<Nothing> = this

override fun updateKeywordLocation(
Expand Down Expand Up @@ -193,6 +199,8 @@ public sealed class OutputCollector<T> private constructor(
) : OutputCollector<ValidationOutput.Flag>(parent, transformer) {
private var valid: Boolean = true
private var hasErrors: Boolean = false
override val isFailFast: Boolean
get() = true
override val output: ValidationOutput.Flag
get() =
if (valid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ internal class JsonSchemaRoot(
var result = true
context.pushSchemaPath(schemaPath, scopeId)
errorCollector.updateKeywordLocation(schemaPath).use {
val failFast = isFailFast
assertions.forEach {
val valid = it.validate(element, context, this)
result = result and valid
if (!result && failFast) {
return@use
}
}
}
context.popSchemaPath()
Expand Down
Loading