Open guisehn opened 6 years ago
Revalidator type check on the root object only works if the type to be validated is an array, but it doesn't work if it's an object.
type
If schema.type is array and the value passed is an object:
schema.type
array
let value = {}; let schema = { type: 'array' }; let result = revalidator.validate(value, schema); console.log(result);
Revalidator returns an error:
{ valid: false, errors: [ { attribute: 'type', property: '', expected: 'array', actual: 'object', message: 'must be of array type' } ] }
I expected the same behavior to happen when schema.type is object, but it doesn't work. See the examples:
object
Example 1:
let value = []; let schema = { type: 'object' }; let result = revalidator.validate(value, schema); console.log(result);
returns
{ valid: true, errors: [] }
Example 2:
let value = 5; let schema = { type: 'object' }; let result = revalidator.validate(value, schema); console.log(result);
Example 3:
let value = 'hi'; let schema = { type: 'object' }; let result = revalidator.validate(value, schema); console.log(result);
{ valid: false, errors: [ { attribute: 'additionalProperties', property: '0', expected: undefined, actual: 'h', message: 'must not exist' }, { attribute: 'additionalProperties', property: '1', expected: undefined, actual: 'i', message: 'must not exist' } ] }
If we expect it to have the same behavior of the array validation, it should be returning something like:
{ valid: false, errors: [ { attribute: 'type', property: '', expected: 'object', actual: 'array', // or "number", or "string" message: 'must be of object type' } ] }
Revalidator
type
check on the root object only works if the type to be validated is an array, but it doesn't work if it's an object.If
schema.type
isarray
and the value passed is an object:Revalidator returns an error:
I expected the same behavior to happen when
schema.type
isobject
, but it doesn't work. See the examples:Example 1:
returns
Example 2:
returns
Example 3:
returns
If we expect it to have the same behavior of the array validation, it should be returning something like: