Skip to content

object().with using nested paths validates when it shouldn't in Joi 14 #1617

@chrismessiah

Description

@chrismessiah

Context

  • node version: v8.11.4
  • joi version: 14.0.0
  • environment: node
  • used with: standalone

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

A new feature in Joi 14 is the ability to use nested paths in or/and/with (among others) as described in #1615. However according to my tests with seem to validate in an unexpected or faulty manner.

const schema = Joi.object().keys({
    a: {
      b: Joi.string()
    },
    c: {
      d: Joi.string()
    }
})
.with("a.b", "c.d");

So if a: {b: "..."} exists we want c: {d: "..."} to also exist.

Which result you had ?

If we have the following input

const data = {
  a: {
    b: "foo"
  }
};

Then the input is considered valid.

What did you expect ?

The input should not be valid as c.d does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug or defect

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions