jakartaee / validation

Jakarta Validation
http://beanvalidation.org
Apache License 2.0
127 stars 54 forks source link

Be able to compose Pattern list with OR expression #157

Open sanmibuh opened 5 years ago

sanmibuh commented 5 years ago

Nowadays @Pattern validator is able to match a list of patterns. But the validation passes if all of pattern matches. It could be helpful having a @Pattern.List configuration for tell the need to pass all (AND composition) or at least one (OR composition)

emmanuelbernard commented 5 years ago

Hey there, I think we discussed it in the past but I can't recall the reason why we did not execute. Have you explore the implications on the spec and group system? The API is the easy part even though what you propose does not allow for nested AND/OR structures.

sanmibuh commented 5 years ago

I have put the same question in the official forum https://discourse.hibernate.org/t/multiple-pattern-validator-with-or/3327

I know that the proposal is simple, but accepting nested AND / OR structure IMHO is cross for all validations. I mean, it could be awesome for grouping different validations. Nowadays Hibernates bean validation implementation could do with @ConstraintComposition annotation. https://docs.jboss.org/hibernate/validator/5.3/reference/en-US/html_single/#section-boolean-constraint-composition.

But this case is a more simple case. Pattern.List actually groups all patterns with AND composition. With this change, the implementation could read this parameter and apply the composition with the desired union operator without having the more complex cross @ConstraintComposition annotation.

Maybe, as the reference implementation could do this, why not adding this annotation as API spec? It could be awesome

emmanuelbernard commented 5 years ago

Ah I see, this would be for Pattern specifically. I read too quickly.