konform-kt / konform

Portable validations for Kotlin
https://www.konform.io
MIT License
654 stars 39 forks source link

Custom validation should allow assigning `dataPath` value #130

Open ronjunevaldoz opened 3 weeks ago

ronjunevaldoz commented 3 weeks ago

Please see related issue: https://github.com/konform-kt/konform/issues/35

image

Steps

addConstraint(dataPath = "confirmPassword") {}
// or automatically catch dataPath from field
CreateBasicAccountInput::confirmPassword required { 
  addConstraint("Passwords should match") {
       it.password == it.confirmPassword
  }
}

Actual

error :dataPath: "", message: "Passwords should match"

Expectations

error: dataPath: "confirmPassword", message: "Passwords should match"

dhoepelman commented 3 weeks ago

See https://github.com/konform-kt/konform/issues/29

ronjunevaldoz commented 3 weeks ago

See #29

I didn't quite see if this shows the correct answer or is it a pending wip. This is not resolve on my end

dhoepelman commented 3 weeks ago

With 0.7.0 and #86 the situation will improve a bit, but this could be better

Validation<CreateBasicAccountInput> {
  validate("confirmPassword", { it.password to it.confirmPassword }) {
    addConstraint("Passwords should match") {
       it.password == it.confirmPassword
    }
  }
}

The above will have the correct path, but ideally addConstraint or similar should allow setting this directly