Skip to content

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

@chrismessiah

Description

@chrismessiah

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.

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions