-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot call method 'hasOwnProperty' of undefined #57
Comments
since jjv throws, this is most definitely an error, and I will gladly fix it. However, we should first agree on what the correct output should be on that schema when called on undefined; My gut feeling is to fail, since the type undefined does NOT have a "foo" property. However, your argument about why it should succeed also seems pretty solid. Would you mind opening an issue in https://github.com/json-schema/JSON-Schema-Test-Suite to discuss this? Once we have a definitive answer from the folks at json-schema I can proceed to fix it (pull requests to fix this are also welcome btw). |
Great idea! I actually posted to the json-schema repo itself, since I'm realizing the official JSON Schema draft actually doesn't specify whether the |
I get the same exception with the following example var env = jjv();
var errors = env.validate({
type: 'object',
properties: {
people: {
type: ['object', 'null'],
properties: {
firstName: {type: 'string'},
lastName: {type: 'string'}
},
required: ['firstName', 'lastname']
},
}
}, {
people: null
}); Is the project still maintained? I could make a pull request if you plan to merge it and tag a new version |
When a JSON schema has a
required
key without a correspondingtype: "object"
, and the JJV validator is passedundefined
for that object, JJV throwsTypeError: Cannot call method 'hasOwnProperty' of undefined
.It appears that JJV calls
hasOwnProperty()
on theundefined
value before checking that the value is in fact an object, resulting in this error.According to json-schema.org:
Perhaps the correct behavior in this case is that when there's a
required: ["foo"]
without a correspondingtype: "object"
, validation will simply succeed?To reproduce the error, run
coffee test.coffee
:...and you will get the following error:
TypeError: Cannot call method 'hasOwnProperty' of undefined
.The text was updated successfully, but these errors were encountered: