konform-kt / konform

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

Add support for conditional/dependent validation #8

Open raderio opened 5 years ago

raderio commented 5 years ago

For example I want to validate an email field, I want to validate it against a regexp pattern, and only it is a valid email I want to check if it is already taken(persisted in database).

nlochschmidt commented 5 years ago

Good idea. I would be open for a pull request for this.

I am not quite sure yet how the DSL should look like. One possibility I could think of would look like this

Person::email {
    inOrder {
        pattern("\\w+@bigcorp.com") hint "Organizers must have a BigCorp email address"
        uniqueInDatabase(dao) hint "Email has been taken"
    }
}
floatdrop commented 2 years ago

@nlochschmidt I wonder if default behaviour should be changed to seqential (eg. fail fast) and accumulate modificator added to support getting all errors from validator.

dhoepelman commented 4 months ago

I would not recommend anyone doing this and keep things like network calls and database lookups separate from the unitial validation, but it would be possible by adding free-form validations and context-dependent validation, so would be fixed by having both #65 and #98