failOnFirstViolation

open override var failOnFirstViolation: Boolean

Whether validations should fail immediately on the first constraint violation, or wait for all the constraints to execute.

When set to true, the first violation constraint will halt the validation, and a failure will be returned immediately without executing the upcoming constraints:

val config = Configuration {
failOnFirstViolation = true
}
val validate = Validator<Any?>(config) {
constrain { false } otherwise { "first message" }
constrain { false } otherwise { "second message" }
}
val failure = validate(null) as ValidationResult.Failure
failure.violations.size // Returns: 1
failure.violations.single().message // Returns: "first message"

When set to false (the default), all the constraints will be executed before returning a result:

val config = Configuration {
failOnFirstViolation = false
}
val validate = Validator<Any?>(config) {
constrain { false } otherwise { "first message" }
constrain { false } otherwise { "second message" }
}
val failure = validate(null) as ValidationResult.Failure
failure.violations.size // Returns: 2