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

Nested errors don't appear to encode path properly #11

Closed
hderms opened this issue Jul 13, 2018 · 0 comments
Closed

Nested errors don't appear to encode path properly #11

hderms opened this issue Jul 13, 2018 · 0 comments

Comments

@hderms
Copy link

hderms commented Jul 13, 2018

This is more or less from your example on the README:

import com.sksamuel.monkeytail.Validator
import com.sksamuel.monkeytail._
import com.sksamuel.monkeytail.ValidatorSyntax._

case class Designation(prefix: String, code: String)
case class Starship(name: String, maxWarp: Double, designation: Designation)

implicit val designationValidator = Validator[Designation]
  .validate(_.prefix)(prefix => prefix != null && (prefix.startsWith("NCC") || prefix.startsWith("NX")))
  .validate(_.code)(!_.isEmpty)

object MaxWarpExceededViolation extends Violation

val starshipValidator = Validator[Starship]
  .validate(_.name)(_ != null)
  .validate(_.maxWarp)(_ < 10)(MaxWarpExceededViolation)
  .valid(_.designation)(designationValidator) // this will require the previous implicit.

val starship = Starship("USS Enterprise", maxWarp = 5.0, designation = Designation("NCC-foo", ""))
val result = starshipValidator(starship)

The output of the result has what appears to be a bug in the path returned:

result: Validated[NonEmptyList[Violation],Starship] = Invalid(NonEmptyList(DefaultViolation(Invalid value: ,Path(List(code)))))

Path(List(code)) should be Path(List(designation, code))

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

No branches or pull requests

2 participants