async-validate icon indicating copy to clipboard operation
async-validate copied to clipboard

Wrong behavior with deep rules

Open rahpuser opened this issue 8 years ago • 5 comments

Using the following description throws and unexpected error:

{
  "type": "object",
  "fields": {
    "testKey": {
      "type": "object",
      "required": true,
      "fields": {
        "anotherTest": [
          {
            "type": "object",
            "required": true,
            "fields": {
              "testField": {
                "type": "string",
                "required": true
              },
            }
          }
        ]
      }
    }
  }
}

schema.validate({ testKey: {} }, (err, res) => {...

This throws the following error: Cannot read property 'testField' of undefined

Is there something wrong in the descriptor or is there something else to configure to make this validation work?

rahpuser avatar Sep 04 '17 22:09 rahpuser

This looks like a bug to me, can you post the full stack trace please?

tmpfs avatar Sep 05 '17 01:09 tmpfs

@tmpfs sure, sorry the delay.


TypeError: Cannot read property 'testField' of undefined
    at iterator (projectRoot/node_modules/async-validate/lib/schema.js:256:34)
    at run (projectRoot/node_modules/async-validate/lib/iterator.js:5:5)
    at mapSeries (projectRoot/node_modules/async-validate/lib/iterator.js:18:12)
    at onValidate (projectRoot/node_modules/async-validate/lib/schema.js:251:9)
    at Fn.object [as test] (projectRoot/node_modules/async-validate/plugin/object.js:31:5)
    at projectRoot/node_modules/async-validate/lib/schema.js:331:15
    at run (projectRoot/node_modules/async-validate/lib/iterator.js:5:5)
    at mapSeries (projectRoot/node_modules/async-validate/lib/iterator.js:18:12)
    at Schema.validate (projectRoot/node_modules/async-validate/lib/schema.js:197:3)
    at iterator (projectRoot/node_modules/async-validate/lib/schema.js:314:18)
    at run (projectRoot/node_modules/async-validate/lib/iterator.js:5:5)
    at mapSeries (projectRoot/node_modules/async-validate/lib/iterator.js:18:12)
    at onValidate (projectRoot/node_modules/async-validate/lib/schema.js:251:9)
    at Fn.object [as test] (projectRoot/node_modules/async-validate/plugin/object.js:31:5)
    at projectRoot/node_modules/async-validate/lib/schema.js:331:15
    at run (projectRoot/node_modules/async-validate/lib/iterator.js:5:5)

rahpuser avatar Sep 06 '17 22:09 rahpuser

Hey,

Sorry for the slow response. I'm super busy building a house so may be a while before I get a chance to take a look at it. Any chance you want to give it a shot and submit a PR?

tmpfs avatar Sep 12 '17 01:09 tmpfs

I have the same problem What time can solve?

Lw-d avatar Oct 31 '17 09:10 Lw-d

Well not so soon, as my laptop just died and I am working on other stuff ;) If either of you can submit a PR with a failing test case it would speed things up.

tmpfs avatar Oct 31 '17 12:10 tmpfs