Skip to content
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

Sets the dataPath for the parent #76

Closed
shihuili1218 opened this issue Aug 21, 2023 · 4 comments
Closed

Sets the dataPath for the parent #76

shihuili1218 opened this issue Aug 21, 2023 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@shihuili1218
Copy link

data class Baby(
    val age: Int
)

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'

@shihuili1218
Copy link
Author

shihuili1218 commented Aug 21, 2023

@nlochschmidt @sksamuel @jillesvangurp @wtomi

Could you please give me some guidance?

@dhoepelman dhoepelman added the enhancement New feature or request label May 10, 2024
@dhoepelman dhoepelman added this to the v0.9.0 milestone Nov 9, 2024
@dhoepelman
Copy link
Collaborator

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"

@dhoepelman
Copy link
Collaborator

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)

@dhoepelman
Copy link
Collaborator

Fixed by #155, to be released in 0.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants