Closed
Description
Context
- node version: 9.8.0
- joi version: 13.1.2
- environment (node, browser): node
- used with (hapi, standalone, ...): standalone
What are you trying to achieve or the steps to reproduce ?
I'm trying to use the .or()
method on a Joi.object
with a reference to a nested key.
const schema = Joi.object({
a: Joi.string(),
b: Joi.object({
c: Joi.string()
})
})
.or("a", "b.c");
schema.validate({ b: { c: 'bc' } });
Which result you had ?
{ error:
{ ValidationError: "value" must contain at least one of [a, b.c]
at Object.exports.process (<myWorkspace>/node_modules/joi/lib/errors.js:196:19)
at internals.Object._validateWithOptions (<myWorkspace>/node_modules/joi/lib/types/any/index.js:668:31)
at internals.Object.validate (<myWorkspace>/node_modules/joi/lib/types/any/index.js:702:21)
at repl:1:13
at Script.runInThisContext (vm.js:65:33)
at REPLServer.defaultEval (repl.js:248:29)
at bound (domain.js:375:14)
at REPLServer.runBound [as eval] (domain.js:388:12)
at REPLServer.onLine (repl.js:501:10)
at REPLServer.emit (events.js:185:15)
isJoi: true,
name: 'ValidationError',
details: [ [Object] ],
_object: { b: [Object] },
annotate: [Function] },
value: { b: { c: 'c' } },
then: [Function: then],
catch: [Function: catch] }
What did you expect ?
I would expect the validation to pass and return the value
{ b: { c: 'bc' } }