Skip to content

Conversation

MPieter
Copy link

@MPieter MPieter commented Aug 27, 2015

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.

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.
@MPieter
Copy link
Author

MPieter commented Aug 27, 2015

The error reports don't seem to be correlated with my changes, right?

@borel
Copy link

borel commented Dec 18, 2015

I had the same issue and have the same solution .
The PR of MPieter will be accepted ?

@olegam
Copy link

olegam commented Jun 18, 2016

Would be great if this fix was merged. Without this fix having more than a single schema dependency does not work.

@tkirda
Copy link

tkirda commented Jul 25, 2016

@trainiac will this be merged?

@DarynHolmes
Copy link

I am getting the same issue... Will this fix be merged?

@trainiac
Copy link
Owner

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]);
}
Copy link

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);
});

Copy link
Owner

@trainiac trainiac left a 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

@trainiac
Copy link
Owner

This will be fixed here #15

@trainiac trainiac closed this Sep 27, 2016
@tkirda
Copy link

tkirda commented Sep 27, 2016

@trainiac thanks!

@trainiac
Copy link
Owner

1.1.5 is on npm now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants