I have a query parameter of date string and set convert option to false. Joi.validate fails and returns error "'startDate' must be a number of milliseconds or valid date string" even though the string is a valid date string.
A string is not a date, it needs to be coerced to validate, convert is almost always needed when validating from a JSON. If you need the original string you can add .raw().
I guess that works. Thanks.
@Marsup I ran into this today. My goal is to convert for Joi validation but keep the original value otherwise. Is there any way to do so? E.g.
let schema = Joi.object().keys({
// format is basically pointless with convert=false
dateStr: Joi.date().format('YYYY-MM-DD').options({ convert: false }),
someNumber: Joi.number()
})
let payload = {
dateStr: '2016-04-07',
someNumber: '17'
}
let result = Joi.attempt(payload, schema)
// want: result.dateStr to be a string, result.someNumber to be a number (not string)
Looking for raw() maybe ?
Looking for
raw()maybe ?
@Marsup exactly, thanks!
Edit: also apparently I should read more closely as you mentioned this above 馃槪
Most helpful comment
Looking for
raw()maybe ?