tmpfs / async-validate

Asynchronous type validation for node and the browser
Other
314 stars 45 forks source link

Wrong behavior with deep rules #63

Open rahpuser opened 7 years ago

rahpuser commented 7 years ago

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?

tmpfs commented 7 years ago

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

rahpuser commented 7 years ago

@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)
tmpfs commented 6 years ago

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?

Lw-d commented 6 years ago

I have the same problem What time can solve?

tmpfs commented 6 years ago

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.