Skip to content
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

Fix recursive schema parsing #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions component.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scripts": [
"tv4.js",
"lang/de.js",
"lang/es.js",
"lang/fr.js",
"lang/nb.js",
"lang/pl-PL.js",
Expand Down
5 changes: 5 additions & 0 deletions source/normalise-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ function normSchema(schema, baseUri) {
if (typeof schema['$ref'] === "string") {
schema['$ref'] = resolveUrl(baseUri, schema['$ref']);
}

if (schema['type'] === 'array' && schema['items'] && hasSameKeys(schema, schema['items'])){
return;
}

for (var key in schema) {
if (key !== "enum") {
normSchema(schema[key], baseUri);
Expand Down
19 changes: 19 additions & 0 deletions source/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ ValidatorContext.prototype.searchSchemas = function (schema, url) {
}
}
}

if (schema['type'] === 'array' && schema['items'] && hasSameKeys(schema, schema['items'])) {
return;
}

for (var key in schema) {
if (key !== "enum") {
if (typeof schema[key] === "object") {
Expand Down Expand Up @@ -395,3 +400,17 @@ function recursiveCompare(A, B) {
}
return false;
}

function hasSameKeys(left, right) {
var leftKeys = Object.keys(left);
var rightKeys = Object.keys(right);
if (leftKeys.length !== rightKeys.length) {
return false;
}
for (var key in leftKeys) {
if (rightKeys.indexOf(key) !== -1) {
return false;
}
}
return true;
}
26 changes: 25 additions & 1 deletion tv4.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tv4.min.js

Large diffs are not rendered by default.