[BUG] getValidationPattern() is unreliable.
Closed this issue · 3 comments
The Problem
\Raml\NamedParameter uses getValidationPattern() to pull type checking regex, as well as the RAML defined "pattern" data.
When the RAML data doesn't include a "pattern" entry, you get the pattern for the type checking. RegEx is slower than PHP type checking with is_string() or is_int() or the like, so that really shouldn't be part of the getter IMO.
However, the real issue is that when a validation pattern is present in the RAML data, you don't have any way to know if you've just validated the value off of the pattern supplied in the RAML data or if you just validated it with a generic type checking method, including the default patterns to match everything one character or longer.
I prefer to perform type and length checking without RegEx to help make my programs more efficient, but if a pattern is present in the RAML data, I'd like to keep with the spec, and validate against it. However, in the current setup, I'm unable to reliably verify that I'm only validating against the RAML supplied pattern.
The solution
Add an optional parameter to force the return of the RAML supplied value if it exists, just like the other getters do.
Hey - I've commented on the pull request regarding this.
Basically I think you're correct. I don't even think the custom validation pattern should be there. It's not from the spec.
Thinking about it further, the best solution may be to merge your pull request, then for version 2 (which looks like it might have to be soon), we remove all the custom validation patterns.
Agreed.
All the custom validation patterns are going to be removed in 2.0.0