-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Array.includes() does not support more than 1 type #133
Comments
Joi will automatically try to do type conversions for you: https://github.com/spumko/joi#skip-conversions |
Right, but that is not the issue. The issue is that Array.includes() isn't working as expected. For example, the following schema doesn't validate properly (but it should) against the objects listed below :
The above schema reads that the object can contain an 'array' key whose type is an Array which can include array values of type String (with min length of 5 chars) or numbers >= 0. With the above schema, I expect the the following objects to be valid, but Joi says that are invalid against the above schema: {"array":[3]} : Error: the value of array must be a string, the value of array must be at least 5 characters long {"array":["12345",3]} : Error: the value of array must be a string, the value of array must be at least 5 characters long I wrote another test, which implies that when (at least) when Number and String are included together, Number is being ignored: it.only('can validate that its elements only include certain types', function(done) {
}); The test output is:
|
The issue is that validation works at the type level, but not via Joi.validate here's one of Joi's tests from array.js: it('should validate array of mixed Numbers & Strings', function (done) {
It passes just fine. here's another version of the test, except that now the array types are part of an object schema: it.skip('should validate array of mixed Numbers & Strings', function() {
The test fails with the following error:
|
Below is a test case that produces the issue. In other words, it only supports homogeneous arrays - not heterogeneous arrays. However, according to the docs, it should be able to support heterogeneous arrays.
The text was updated successfully, but these errors were encountered: