konform-kt / konform

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

Programatically list all errors #21

Open AWinterman opened 4 years ago

AWinterman commented 4 years ago

Currently, there is no way to programatically list all the errors associated with an object.

Yes, you can call ValidationResult.errors but the dataPath is computed in a non-public method, and there's no way to map it back to the property that errored without duplicated the computation.

Essentially I would like to do the following:

  1. define a check for each property
  2. map that check to a wire representation
  3. have control over the wire representation.

The Validation.dataPath method is a serialized representaiton of the error. I need a kotlin one.

I can almost get there simply by passing around references to the object properties (which has its own problems), but the handling for arrays puts it over the edge of inconvenience.

nlochschmidt commented 4 years ago

What do you mean by "map that check to a wire representation".

Could you provide a minimal example of the DSL/API you'd like to see?

AWinterman commented 4 years ago

if the errors object simply had a reference to the properties that are erroring, that would be sufficient. Maybe a linked list of the properties that make up the path?