Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joi.object().or() does not support nested paths #1477

Closed
Wenzil opened this issue Apr 17, 2018 · 7 comments
Closed

Joi.object().or() does not support nested paths #1477

Wenzil opened this issue Apr 17, 2018 · 7 comments
Assignees
Labels
breaking changes Change that can breaking existing code feature New functionality or improvement
Milestone

Comments

@Wenzil
Copy link

Wenzil commented Apr 17, 2018

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' } }
@Wenzil Wenzil changed the title or() does not support nested paths Joi.object().or() does not support nested paths Apr 17, 2018
@BolajiOlajide
Copy link
Contributor

I'd like to work on this. Can I get assigned to it?

@Marsup
Copy link
Collaborator

Marsup commented Jul 4, 2018

I can't assign people outside of the org but sure.

@Marsup
Copy link
Collaborator

Marsup commented Aug 1, 2018

Marked another request as duplicate 👆, it was clear in my mind that it needed to happen on all the APIs but just stating it clearly.

Need help @BolajiOlajide ? :)

@BolajiOlajide
Copy link
Contributor

Hey @Marsup ,

I'm trying to figure a way to ensure my logic works regardless of how nested the object is. The raw implementation is done, just need to ensure everything works perfectly regardless.

@Marsup Marsup added the breaking changes Change that can breaking existing code label Aug 6, 2018
@Marsup Marsup self-assigned this Aug 6, 2018
@Marsup Marsup added this to the 14.0.0 milestone Aug 6, 2018
Marsup added a commit that referenced this issue Sep 29, 2018
…-objects

#1477 Add Support for nested path with Joi.object().or(), .nand(), .and(), .with(), .without(), .xor()
@BolajiOlajide
Copy link
Contributor

I believe this can be closed now @Marsup

@Marsup
Copy link
Collaborator

Marsup commented Oct 2, 2018

It will be when I merge v14 to master.

@arb
Copy link
Contributor

arb commented Oct 2, 2018

And when is that going to be? 😏

@Marsup Marsup closed this as completed Oct 14, 2018
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes Change that can breaking existing code feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

5 participants