Skip to content

Commit

Permalink
improved error reporting for "required" keyword with large size schema,
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Jun 30, 2015
1 parent fd61168 commit 5fc0b18
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/dot/required.jst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
} else {
{{??}}
var schema{{=$lvl}} = validate.schema{{=$schemaPath}};
{{ it.errorPath = ($currentErrorPath + ' + "[\'" + schema' + $lvl + '[i] + "\']"').replace('" + "', ''); }}

for (var i = 0; i < schema{{=$lvl}}.length; i++) {
var {{=$valid}} = data[schema{{=$lvl}}[i]] !== undefined;
Expand All @@ -43,13 +44,14 @@
{{~}}
{{??}}
var schema{{=$lvl}} = validate.schema{{=$schemaPath}};
{{ it.errorPath = ($currentErrorPath + ' + "[\'" + schema' + $lvl + '[i] + "\']"').replace('" + "', ''); }}

for (var i = 0; i < schema{{=$lvl}}.length; i++) {
var {{=$valid}} = data[schema{{=$lvl}}[i]] !== undefined;
if (!{{=$valid}}) break;
if (!{{=$valid}}) {
{{# def.error:'required' }}
}
}

{{# def.checkError:'required' }}
{{?}}
{{?}}

Expand Down
10 changes: 7 additions & 3 deletions lib/dotjs/required.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ module.exports = function anonymous(it) {
}
out += ' } else { ';
} else {
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; for (var i = 0; i < schema' + ($lvl) + '.length; i++) { var ' + ($valid) + ' = data[schema' + ($lvl) + '[i]] !== undefined; if (!' + ($valid) + ') break; } if (!' + ($valid) + ') { ';
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
it.errorPath = ($currentErrorPath + ' + "[\'" + schema' + $lvl + '[i] + "\']"').replace('" + "', '');
out += ' for (var i = 0; i < schema' + ($lvl) + '.length; i++) { var ' + ($valid) + ' = data[schema' + ($lvl) + '[i]] !== undefined; if (!' + ($valid) + ') break; } if (!' + ($valid) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'properties ' + ($schema.slice(0, 7).join(", "));
if ($schema.length > 7) {
Expand Down Expand Up @@ -115,7 +117,9 @@ module.exports = function anonymous(it) {
}
}
} else {
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; for (var i = 0; i < schema' + ($lvl) + '.length; i++) { var ' + ($valid) + ' = data[schema' + ($lvl) + '[i]] !== undefined; if (!' + ($valid) + ') break; } if (!' + ($valid) + ') { ';
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
it.errorPath = ($currentErrorPath + ' + "[\'" + schema' + $lvl + '[i] + "\']"').replace('" + "', '');
out += ' for (var i = 0; i < schema' + ($lvl) + '.length; i++) { var ' + ($valid) + ' = data[schema' + ($lvl) + '[i]] !== undefined; if (!' + ($valid) + ') { ';
if (it.wasTop && $breakOnError) {
out += ' validate.errors = [ { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'properties ' + ($schema.slice(0, 7).join(", "));
if ($schema.length > 7) {
Expand All @@ -137,7 +141,7 @@ module.exports = function anonymous(it) {
}
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; ';
}
out += ' } ';
out += ' } } ';
}
}
it.errorPath = $currentErrorPath;
Expand Down
2 changes: 1 addition & 1 deletion spec/errors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Validation errors', function () {
});


it.skip('required validation and errors for large data/schemas', function() {
it('required validation and errors for large data/schemas', function() {
var schema = { required: [] }
, data = {}
, invalidData1 = {}
Expand Down

0 comments on commit 5fc0b18

Please sign in to comment.