Skip to content

joi.ref doesn't work properly with max() function for dependant dates  #1350

@jeurrutia

Description

@jeurrutia

Context

  • node version: 8.9.0
  • joi version: 10.6.0
  • environment (node, browser): node
  • used with (hapi, standalone, ...): hapi

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

When trying to do the validation from a date dependant for another one and using joi.ref(...) an error related to a bad example occurs.

Here the code snippet to reproduce the problem:

server.route({
     method: 'GET',
     path: 'foo',
     handler: (request, reply) => reply('OK'),
      config: {
        validate: {
          query: joi.object({           
            fromDate: joi.date()
              .iso()
              .required()
              .max(joi.ref('toDate'))             
              .example(new Date('2017-10-25T00:00:00.000Z')),
            toDate: joi.date()
              .iso()
              .default(() => new Date(), 'Now')
              .max('now')
              .example(new Date('2017-10-28T00:00:00.000Z')),
          }).unknown(),        
        },
      },
    });

Which result you had ?

error: {
      "message": "Bad example: \"value\" references \"toDate\" which is not a date",
      "name": "Error",
...
}

What did you expect ?

Return json data expected for this API.

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions