-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Context
- node version: 6.10
- joi version: 10.6.0
- environment (node, browser): node
- used with (hapi, standalone, ...): standalone
- any other relevant information:
What are you trying to achieve or the steps to reproduce ?
I am trying to validate a variable (array of length two) which is a location data, with lat long.
I want to validate the array such that -90 < lat < 90 and -180 < long<180 also make sure that both the values are present.
Location data is in GeoJSON hence data at 0 position should be longitude and latitude at pos 1. And subsequent rules should be applied for testing.
Describe your issue here, include schemas and inputs you are validating if needed.
var schema = Joi.object().keys({location: Joi.array().ordered(Joi.number().min(-180).max(180).label('longitude').required(), Joi.number().min(-90).max(90).label('latitude').required()).label('location').required()});
var input = {location: [undefined, 10]};
Joi.validate(input,schema, {abortEarly: false});Which result you had ?
{ error:
{ ValidationError: child "location" fails because ["location" must not be a sparse array, "location" does not contain [latitude]]
at Object.exports.process (/home/rohit/dev/upwork/streetography/joi/joi/node_modules/joi/lib/errors.js:196:19)
at _validateWithOptions (/home/rohit/dev/upwork/streetography/joi/joi/node_modules/joi/lib/types/any/index.js:668:31)
at root.validate (/home/rohit/dev/upwork/streetography/joi/joi/node_modules/joi/lib/index.js:139:23)
at repl:1:5
at sigintHandlersWrap (vm.js:22:35)
at sigintHandlersWrap (vm.js:73:12)
at ContextifyScript.Script.runInThisContext (vm.js:21:12)
at REPLServer.defaultEval (repl.js:346:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
isJoi: true,
name: 'ValidationError',
details: [ [Object], [Object] ],
_object: { location: [Object] },
annotate: [Function] },
value: { location: [ undefined, 5 ] },
then: [Function: then],
catch: [Function: catch] }
What did you expect ?
observe the error message: "location does not contain [latitude]", should it rather not be "longitude" ?
because the first parameter is undefined, should not the output specify which of the input index has the error? (here in this case longitude because we are using label)?
Let me know if you think this is a bug (or if this is intended and I am using this feature wrongly) And if there is something i can do to fix it (would be happy to make a PR if needed)
Thank you for the time.