removed potentially leaking "valid" variable
parent
c441624009
commit
568e76a351
|
@ -3,9 +3,9 @@
|
|||
|
||||
{{? it.resolveRef($schema) }}
|
||||
var result{{=$lvl}} = validateRef('{{=$schema}}', data{{=$dataLvl}}, dataPath{{=$dataLvl}});
|
||||
valid = result{{=$lvl}}.valid;
|
||||
if (!valid) validate.errors.push.apply(validate.errors, result{{=$lvl}}.errors);
|
||||
var valid{{=$lvl}} = result{{=$lvl}}.valid;
|
||||
if (!valid{{=$lvl}}) validate.errors.push.apply(validate.errors, result{{=$lvl}}.errors);
|
||||
{{??}}
|
||||
{{# def.error:'$ref' }}
|
||||
valid = false;
|
||||
var valid{{=$lvl}} = false;
|
||||
{{?}}
|
||||
|
|
|
@ -19,5 +19,3 @@ var valid{{=$lvl}} = true;
|
|||
{{~}}
|
||||
|
||||
{{= $closingBraces }}
|
||||
|
||||
valid = valid{{=$lvl}};
|
|
@ -25,5 +25,3 @@ var valid{{=$lvl}} = false;
|
|||
{{= $closingBraces }}
|
||||
|
||||
if (valid{{=$lvl}}) validate.errors.length = errs{{=$lvl}};
|
||||
|
||||
valid = valid{{=$lvl}};
|
|
@ -52,5 +52,3 @@ var valid{{=$lvl}};
|
|||
valid{{=$lvl}} = errs{{=$lvl}} == validate.errors.length;
|
||||
|
||||
{{# def.cleanUp }}
|
||||
|
||||
valid = valid{{=$lvl}};
|
|
@ -6,6 +6,6 @@
|
|||
}}
|
||||
|
||||
var itemsHash{{=$lvl}} = {{= JSON.stringify($itemsHash) }};
|
||||
var valid = itemsHash{{=$lvl}}[stableStringify(data{{=$dataLvl}})] || false;
|
||||
var valid{{=$lvl}} = itemsHash{{=$lvl}}[stableStringify(data{{=$dataLvl}})] || false;
|
||||
|
||||
{{# def.checkError:'enum' }}
|
||||
{{# def.checkErrorLvl:'enum' }}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
{{# def.setup:'format' }}
|
||||
|
||||
var format{{=$lvl}} = formats['{{=$schema}}'];
|
||||
var valid = typeof format{{=$lvl}} == 'function'
|
||||
? format{{=$lvl}}(data{{=$dataLvl}})
|
||||
: !format{{=$lvl}} || format{{=$lvl}}.test(data{{=$dataLvl}});
|
||||
var valid{{=$lvl}} = typeof format{{=$lvl}} == 'function'
|
||||
? format{{=$lvl}}(data{{=$dataLvl}})
|
||||
: !format{{=$lvl}} || format{{=$lvl}}.test(data{{=$dataLvl}});
|
||||
|
||||
{{# def.checkError:'format' }}
|
||||
{{# def.checkErrorLvl:'format' }}
|
||||
{{??}}
|
||||
var valid = true;
|
||||
var valid{{=$lvl}} = true;
|
||||
{{?}}
|
||||
|
|
|
@ -82,5 +82,3 @@ var valid{{=$lvl}};
|
|||
valid{{=$lvl}} = errs{{=$lvl}} == validate.errors.length;
|
||||
|
||||
{{# def.cleanUp }}
|
||||
|
||||
valid = valid{{=$lvl}};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'maxItems' }}
|
||||
|
||||
var valid = data{{=$dataLvl}}.length <= {{=$schema}};
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}}.length <= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'maxItems' }}
|
||||
{{# def.checkErrorLvl:'maxItems' }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'maxLength' }}
|
||||
|
||||
var valid = data{{=$dataLvl}}.length <= {{=$schema}};
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}}.length <= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'maxLength' }}
|
||||
{{# def.checkErrorLvl:'maxLength' }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'maxProperties' }}
|
||||
|
||||
var valid = Object.keys(data{{=$dataLvl}}).length <= {{=$schema}};
|
||||
var valid{{=$lvl}} = Object.keys(data{{=$dataLvl}}).length <= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'maxProperties' }}
|
||||
{{# def.checkErrorLvl:'maxProperties' }}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
, $op = $exclusive ? '<' : '<=';
|
||||
}}
|
||||
|
||||
var valid = data{{=$dataLvl}} {{=$op}} {{=$schema}};
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}} {{=$op}} {{=$schema}};
|
||||
|
||||
{{# def.checkError:'maximum' }}
|
||||
{{# def.checkErrorLvl:'maximum' }}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'minItems' }}
|
||||
|
||||
var valid = data{{=$dataLvl}}.length >= {{=$schema}};
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}}.length >= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'minItems' }}
|
||||
{{# def.checkErrorLvl:'minItems' }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'minLength' }}
|
||||
|
||||
var valid = data{{=$dataLvl}}.length >= {{=$schema}};
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}}.length >= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'minLength' }}
|
||||
{{# def.checkErrorLvl:'minLength' }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'minProperties' }}
|
||||
|
||||
var valid = Object.keys(data{{=$dataLvl}}).length >= {{=$schema}};
|
||||
var valid{{=$lvl}} = Object.keys(data{{=$dataLvl}}).length >= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'minProperties' }}
|
||||
{{# def.checkErrorLvl:'minProperties' }}
|
|
@ -6,6 +6,6 @@
|
|||
, $op = $exclusive ? '>' : '>=';
|
||||
}}
|
||||
|
||||
var valid = data{{=$dataLvl}} {{=$op}} {{=$schema}};
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}} {{=$op}} {{=$schema}};
|
||||
|
||||
{{# def.checkError:'minimum' }}
|
||||
{{# def.checkErrorLvl:'minimum' }}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
{{# def.setup:'multipleOf' }}
|
||||
|
||||
var division{{=$lvl}} = data{{=$dataLvl}} / {{=$schema}};
|
||||
var valid = division{{=$lvl}} === parseInt(division{{=$lvl}});
|
||||
var valid{{=$lvl}} = division{{=$lvl}} === parseInt(division{{=$lvl}});
|
||||
|
||||
{{# def.checkError:'multipleOf' }}
|
||||
{{# def.checkErrorLvl:'multipleOf' }}
|
||||
|
|
|
@ -17,5 +17,3 @@ valid{{=$lvl}} = !valid{{=$lvl}};
|
|||
|
||||
if (valid{{=$lvl}}) validate.errors.length = errs{{=$lvl}};
|
||||
else {{# def.error:'not' }}
|
||||
|
||||
valid = valid{{=$lvl}};
|
|
@ -30,5 +30,3 @@ var valid{{=$lvl}} = validCount{{=$lvl}} == 1;
|
|||
|
||||
if (valid{{=$lvl}}) validate.errors.length = errs{{=$lvl}};
|
||||
else {{# def.error:'oneOf' }}
|
||||
|
||||
valid = valid{{=$lvl}};
|
|
@ -2,6 +2,6 @@
|
|||
{{# def.setup:'pattern' }}
|
||||
|
||||
{{ new RegExp($schema); /* test if regexp is valid to fail at compile time rather than in eval */}}
|
||||
var valid = /{{=$schema}}/.test(data{{=$dataLvl}});
|
||||
var valid{{=$lvl}} = /{{=$schema}}/.test(data{{=$dataLvl}});
|
||||
|
||||
{{# def.checkError:'pattern' }}
|
||||
{{# def.checkErrorLvl:'pattern' }}
|
||||
|
|
|
@ -134,5 +134,3 @@ var valid{{=$lvl}} = true;
|
|||
valid{{=$lvl}} = errs{{=$lvl}} == validate.errors.length;
|
||||
|
||||
{{# def.cleanUp }}
|
||||
|
||||
valid = valid{{=$lvl}};
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
{{# def.setup:'required' }}
|
||||
|
||||
{{? $schema.length <= 100 }}
|
||||
valid = {{~ $schema:$property:$i }}
|
||||
{{? $i}} && {{?}}
|
||||
data{{=$dataLvl}}.hasOwnProperty('{{= it.escapeQuotes($property) }}')
|
||||
{{~}};
|
||||
valid{{=$lvl}} = {{~ $schema:$property:$i }}
|
||||
{{? $i}} && {{?}}
|
||||
data{{=$dataLvl}}.hasOwnProperty('{{= it.escapeQuotes($property) }}')
|
||||
{{~}};
|
||||
{{??}}
|
||||
var schema{{=$lvl}} = validate.schema{{=$schemaPath}};
|
||||
|
||||
for (var i{{=$lvl}} = 0; i{{=$lvl}} < schema{{=$lvl}}.length; i{{=$lvl}}++) {
|
||||
valid = data.hasOwnProperty(schema{{=$lvl}}[i{{=$lvl}}]);
|
||||
if (!valid) break;
|
||||
valid{{=$lvl}} = data.hasOwnProperty(schema{{=$lvl}}[i{{=$lvl}}]);
|
||||
if (!valid{{=$lvl}}) break;
|
||||
}
|
||||
{{?}}
|
||||
|
||||
{{# def.checkError:'required' }}
|
||||
{{# def.checkErrorLvl:'required' }}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
{{ var $isArray = Array.isArray($schema); }}
|
||||
|
||||
{{? $isArray }}
|
||||
var valid = {{= it.checkDataTypes($schema, $dataLvl) }};
|
||||
var valid{{=$lvl}} = {{= it.checkDataTypes($schema, $dataLvl) }};
|
||||
{{??}}
|
||||
var valid = {{= it.checkDataType($schema, $dataLvl) }};
|
||||
var valid{{=$lvl}} = {{= it.checkDataType($schema, $dataLvl) }};
|
||||
{{?}}
|
||||
|
||||
{{# def.checkError:'type' }}
|
||||
{{# def.checkErrorLvl:'type' }}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'uniqueItems' }}
|
||||
|
||||
var valid = true;
|
||||
var valid{{=$lvl}} = true;
|
||||
|
||||
{{? $schema && it.opts.uniqueItems !== false }}
|
||||
if (data{{=$dataLvl}}.length > 1) {
|
||||
|
@ -10,12 +10,12 @@ var valid = true;
|
|||
for (;i{{=$lvl}}--;) {
|
||||
for (j{{=$lvl}} = i{{=$lvl}}; j{{=$lvl}}--;) {
|
||||
if (equal(data{{=$dataLvl}}[i{{=$lvl}}], data{{=$dataLvl}}[j{{=$lvl}}])) {
|
||||
valid = false;
|
||||
valid{{=$lvl}} = false;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid) {{# def.error:'uniqueItems' }}
|
||||
{{# def.checkErrorLvl:'uniqueItems' }}
|
||||
}
|
||||
{{?}}
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
, $closingBraces2 = '';
|
||||
}}
|
||||
|
||||
var valid = true;
|
||||
/*var valid = true;*/
|
||||
var valid{{=$lvl}} = true;
|
||||
|
||||
{{~ it.RULES:$rulesGroup }}
|
||||
|
@ -60,7 +60,7 @@
|
|||
{{? $shouldUseRule($rule) }}
|
||||
{{= $rule.code(it) }}
|
||||
{{? $breakOnErrors }}
|
||||
if (valid) {
|
||||
if (valid{{=$lvl}}) {
|
||||
{{ $closingBraces1 += '}'; }}
|
||||
{{?}}
|
||||
{{?}}
|
||||
|
@ -72,7 +72,7 @@
|
|||
{{? $rulesGroup.type }} } {{?}}
|
||||
|
||||
{{? $breakOnErrors }}
|
||||
if (valid) {
|
||||
if (valid{{=$lvl}}) {
|
||||
{{ $closingBraces2 += '}'; }}
|
||||
{{?}}
|
||||
{{?}}
|
||||
|
|
|
@ -60,14 +60,14 @@ describe('JSON-Schema tests', function () {
|
|||
describe(file.name, function() {
|
||||
var testSets = require(file.path);
|
||||
testSets.forEach(function (testSet) {
|
||||
// if (testSet.description != 'invalid string value for default') return;
|
||||
// if (testSet.description != 'allOf with base schema') return;
|
||||
describe(testSet.description, function() {
|
||||
// it(testSet.description, function() {
|
||||
var validate = ajv.compile(testSet.schema);
|
||||
var fullValidate = fullAjv.compile(testSet.schema);
|
||||
|
||||
testSet.tests.forEach(function (test) {
|
||||
// if (test.description != 'valid when property is specified') return;
|
||||
// if (test.description != 'valid') return;
|
||||
// console.log(testSet.schema, '\n\n***\n\n', validate.toString());
|
||||
it(test.description, function() {
|
||||
var valid = validate(test.data);
|
||||
|
|
Loading…
Reference in New Issue