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

Function to retrieve the errorsMap of an Invalid ValidationResult: #18

Conversation

silversoul93
Copy link

  • errorsMap function added; it returns a Map of the errors; NB. the errors object visibility has not been modified;
  • a simple test has been added.

 - errorsMap function added; it returns a Map of the errors; NB. the errors object visibility has not been modified;
 - a simple test has been added.
@nlochschmidt
Copy link
Member

nlochschmidt commented Mar 15, 2020

@silversoul93 Thanks for your contribution.

I've just released version 0.2.0 with an implementation I had done a while back but haven't been able to publish due to the recent changes around kotlin MPP setup.

There is now a public errors property on the ValidationResult which gives you access to the ValidationErrors. You can convert that to the map that you have in mind by declaring your own extension on ValidationResult:

fun ValidationResult<*>.errorMap(): Map<String, List<String>> {
    return errors.groupBy({ it.dataPath.removePrefix(".") }) { it.message }
}

note the key transform using it.dataPath.removePrefix(".") because the dataPath typically starts with a ..

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

Successfully merging this pull request may close these issues.

2 participants