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

Support Peers as References for nested objects which use .and, .or, .nand, .xor, .with #1553

Closed
chrismessiah opened this issue Jul 31, 2018 · 1 comment
Assignees
Labels
feature New functionality or improvement

Comments

@chrismessiah
Copy link

Describe the problem you are trying to fix (provide as much context as possible)

Currently it is not possible to create a schema with nested objects where xor and nand checks are applied among the others with peers as input parameter. Please see the following schema as an example:

Joi.object().keys({
  a: {
    x: Joi.number(),
  },
  b: {
    y: Joi.string(),
    z: Joi.string(),
  }
})

The problem is that the checks which use peers only applies to siblings and not the sublings' childrens. For example, say we want to perform an xor check on x and z then we cannot use object.xor() as its parameter does not accept a reference such as a.x and b.z.

Which API (or modification of the current API) do you suggest to solve that problem ?

I suggest using references where peers are used today for the following functions

object.and(peers)
object.nand(peers)
object.or(peers)
object.xor(peers)
object.with(key, peers)
object.without(key, peers)

That way, the schema could be created like this with the addition of .xor('a.x', 'b.z') in the end

Joi.object().keys({
  a: {
    x: Joi.number(),
  },
  b: {
    y: Joi.string(),
    z: Joi.string(),
  }
}).xor('a.x', 'b.z')

Are you ready to work on a pull request if your suggestion is accepted ?

Unfortunately not.

@Marsup Marsup self-assigned this Aug 1, 2018
@Marsup Marsup added the request label Aug 1, 2018
@Marsup
Copy link
Collaborator

Marsup commented Aug 1, 2018

I'll consider this a duplicate of #1477, this request covers more methods but it's basically the same and all should support this.

@Marsup Marsup closed this as completed Aug 1, 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
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

3 participants