konform-kt / konform

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

Recursive validation support #74

Open jishindev opened 1 year ago

jishindev commented 1 year ago

Did not find anything related in the issues tab, so creating one to understand whats possible.

I have a set of data classes where one class references itself as a List. I'm unable to find a way to write a validator that can support this. Please share your thoughts on what can be done here.

Sample data classes -

data class Section(val components: List<Component>) {
    data class Component(val subComponents: List<Component>)
}
jishindev commented 1 year ago

Resurfacing. Would appreciate any sort of inputs, possible timelines or workarounds to solve for the above case.

dhoepelman commented 6 months ago

did you try a lazy initializer and function ref to solve the self-reference? Not 100% sure you need the lazy, just the function might be enogh.

val validateComponent: Validation<Component> by lazy {
    Component::subComponents onEach {
      run(validateComponentRef())
    }
}
private fun validateComponentRef(): Validation<Component> = validateComponent