hapijs / joi-date

Joi extensions for dates
Other
83 stars 25 forks source link

Issue with optional date #2

Closed bnadim closed 7 years ago

bnadim commented 7 years ago

Context

What are you trying to achieve or the steps to reproduce ?

Fields with format option become required even if they are written as optional

const BaseJoi = require('joi')
const Extension = require('joi-date-extensions')
const Joi = BaseJoi.extend(Extension)

const schema = Joi.object().required().keys({
    date: Joi.date().format('YYYY-MM-DD').optional()
});

const data = { }

Joi.validate(data, schema, { allowUnknown: true }, (err, validatedData) => {
    if (err) {
        console.log('Validation error : ', err)
    } else {
        console.log('Validation success')
    }
})

Which result you had ?

'"date" must be a string with one of the following formats YYYY-MM-DD'

What did you expect ?

Data should be a valid result

Marsup commented 7 years ago

Thanks for the report, patch published.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.