Closed shihuili1218 closed 18 hours ago
@nlochschmidt @sksamuel @jillesvangurp @wtomi
Could you please give me some guidance?
How would you expect this to interact with nested validations?
data class Baby(val age: Int)
val babyValidation = Validation<Baby> {
path = Baby::class
Baby::age { exclusiveMaximum(5) }
}
val invalidBaby = Baby(5)
// "Baby.age must be less than 5"
println(babyValidation.validate(notBaby).errors)
data class Parent(val babies: List<Baby>)
val parentValidation = Validation<Parent> { babies onEach { run(babyValidation) } }
val invalidParent = Parent(listOf(invalidBaby))
println(parentValidation.validate(invalidParent).errors)
// ".babies[0].age must be less than 5"
// ".babies[0].Baby.age must be less than 5"
Likely adding this to 0.9.0 with API:
val validation: Validation<Baby> { ... }
val validationWithClass = validation.prependPath(PathSegment.toPathSegment(Baby::class)))
// ".age must be less than 5"
println(validation.validate(notBaby).error)
// "Baby.age must be less than 5"
println(validationWithClass.validate(notBaby).error)
Fixed by #155, to be released in 0.9.0
The current error message is '. age must be less than 5 '. I add Baby before .age. e.g: 'Baby. age must be less than 5'