-
Notifications
You must be signed in to change notification settings - Fork 14
Bugfix for validate() #5
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
Conversation
When using the schema dependencies, I got the exception: TypeError: Parameter 'url' must be a string, not number at Url.parse (url.js:107:11) at urlParse (url.js:101:5) at Object.urlResolve [as resolve] (url.js:404:10) at Validator.addSubSchema (/.../node_modules/express-jsonschema/node_modules/jsonschema/lib/validator.js:61:36) at Validator.addSchema (/.../node_modules/express-jsonschema/node_modules/jsonschema/lib/validator.js:42:8) at Array.forEach (native) at validate (/.../node_modules/express-jsonschema/index.js:164:28) at Object.<anonymous> at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) This is caused by: schemaDependencies.forEach(callBack) -> The callback takes element value, index, and array. This gets bind to the addSchema function, which will lead to a wrong uri. As can be seen from the original implementation of the addSchema function: https://github.com/tdegrunt/jsonschema/blob/master/lib/validator.js#L37 Changing this to a normal for-loop fixes the issue.
The error reports don't seem to be correlated with my changes, right? |
I had the same issue and have the same solution . |
Would be great if this fix was merged. Without this fix having more than a single schema dependency does not work. |
@trainiac will this be merged? |
I am getting the same issue... Will this fix be merged? |
Hey all! Sorry for the delay. I took a year off but am back now and will be responding to any issues as they come in now. I'll take a look at this and get it merged ASAP. |
schemaDependencies.forEach(validator.addSchema.bind(validator)); | ||
for(var i = 0; i < schemaDependencies.length; i++) { | ||
validator.addSchema(schemaDependencies[i]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simpler:
schemaDependencies.forEach(function (dependency) {
validator.addSchema(dependency);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tkirda. I've created a branch with your proposed change and added some tests
This will be fixed here #15 |
@trainiac thanks! |
1.1.5 is on npm now |
When using the schema dependencies, I got the exception:
TypeError: Parameter 'url' must be a string, not number
at Url.parse (url.js:107:11)
at urlParse (url.js:101:5)
at Object.urlResolve as resolve
at Validator.addSubSchema (/.../node_modules/express-jsonschema/node_modules/jsonschema/lib/validator.js:61:36)
at Validator.addSchema (/.../node_modules/express-jsonschema/node_modules/jsonschema/lib/validator.js:42:8)
at Array.forEach (native)
at validate (/.../node_modules/express-jsonschema/index.js:164:28)
at Object.
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
This is caused by: schemaDependencies.forEach(callBack)
-> The callback takes element value, index, and array. This gets bind to the addSchema function, which will lead to a wrong uri.
As can be seen from the original implementation of the addSchema function:
https://github.com/tdegrunt/jsonschema/blob/master/lib/validator.js#L37
Changing this to a normal for-loop fixes the issue.