konform-kt / konform

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

Remove internal access modifier to make errors Map accessible from outside #13

Closed KennethWussmann closed 4 years ago

KennethWussmann commented 5 years ago

Hey! This fixes #3. As there was no real result from the issue comments and I think everyone would be fine to at least have access to the errors, the easiest way would be to just expose the errors map to everyone.

Thanks, Kenneth

jeminglin commented 5 years ago

Will this be merged into master?

darren-bell-nanthealth commented 5 years ago

Please, can this be merged? I tried to work around the access using reflection, but of course, there is no reflection available in JS.

Thanks for this useful library!

nikarh commented 4 years ago

Is there any particular reason why this PR can't be merged?

KennethWussmann commented 4 years ago

It seems like this project is no longer actively maintained.

When you are on the JVM you can use reflections to bypass the access restriction:

fun <T> ValidationResult<T>.errors(): Map<List<String>, List<String>> {
    return if (this is Invalid) {
        val errorsProp = this::class.memberProperties.first { it.name == "errors" }
        errorsProp.getter.call(this) as Map<List<String>, List<String>>
    } else emptyMap()
}