joi icon indicating copy to clipboard operation
joi copied to clipboard

Validation - only allow SINGLE LAYER of nesting for a property whose value is an object

Open joshuaquek opened this issue 2 years ago • 0 comments

Support plan

  • is this issue currently blocking your project? (yes/no):
  • NO
  • is this issue affecting a production system? (yes/no):
  • NO

Context

  • node version: 14
  • module version: 17
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): expressjs
  • any other relevant information: nil

What problem are you trying to solve?

Is there a way to only allow a SINGLE layer for a property which is an object? meaning no nesting... lets take the following example:

{
  "hello": {
    "foo": 1,
    "bar": 2
  },
  "world": 3
}

the property hello is an object of {"foo": 1, "bar": 2}.

This should pass validation.

If we were to add an object that is further nested, then it will fail, for example:

{
  "hello": {
    "foo": 1,
    "bar": {
      "good": 4,
      "bye": 5
    }
  },
  "world": 3
}

In essense, how do I ensure only a single layer and no nesting for a selected property, which has an object as a value?

Do you have a new or modified API suggestion to solve the problem?

No

joshuaquek avatar Aug 20 '21 08:08 joshuaquek