refactored properties rule
parent
67762549d8
commit
4a7a586bac
|
@ -1,3 +1,18 @@
|
|||
{{## def.validateProperty:useKey:
|
||||
var _data = data[{{= useKey }}]
|
||||
, _dataType = getDataType(_data)
|
||||
, _dataPath = dataPath + '.' + {{= useKey }}
|
||||
, result = ({{= it._validate($it) }})(_data, _dataType, _dataPath);
|
||||
|
||||
if (!result.valid) {
|
||||
{{? it.opts.allErrors }}
|
||||
errors.push.apply(errors, result.errors);
|
||||
{{??}}
|
||||
return result;
|
||||
{{?}}
|
||||
}
|
||||
#}}
|
||||
|
||||
function (data, dataType, dataPath) {
|
||||
'use strict';
|
||||
|
||||
|
@ -96,18 +111,7 @@ function (data, dataType, dataPath) {
|
|||
$it.schemaPath = it.parentSchemaPath + '.additionalProperties';
|
||||
}}
|
||||
|
||||
var _data = data[key]
|
||||
, _dataType = getDataType(_data)
|
||||
, _dataPath = dataPath + '.' + key
|
||||
, result = ({{= it._validate($it) }})(_data, _dataType, _dataPath);
|
||||
|
||||
if (!result.valid) {
|
||||
{{? it.opts.allErrors }}
|
||||
errors.push.apply(errors, result.errors);
|
||||
{{??}}
|
||||
return result;
|
||||
{{?}}
|
||||
}
|
||||
{{# def.validateProperty:'key' }}
|
||||
{{?}}
|
||||
}
|
||||
}
|
||||
|
@ -124,18 +128,9 @@ function (data, dataType, dataPath) {
|
|||
}}
|
||||
|
||||
if (data.hasOwnProperty('{{= $propertyKey }}')) {
|
||||
var _data = data['{{= $propertyKey }}']
|
||||
, _dataType = getDataType(_data)
|
||||
, _dataPath = dataPath + '.{{= $propertyKey }}'
|
||||
, result = ({{= it._validate($it) }})(_data, _dataType, _dataPath);
|
||||
|
||||
if (!result.valid) {
|
||||
{{? it.opts.allErrors }}
|
||||
errors.push.apply(errors, result.errors);
|
||||
{{??}}
|
||||
return result;
|
||||
{{?}}
|
||||
}
|
||||
{{ /* TODO cache data types and paths by keys for patternProperties */ }}
|
||||
{{ var useKey = '"' + $propertyKey + '"'; }}
|
||||
{{# def.validateProperty:useKey }}
|
||||
}
|
||||
{{?}}
|
||||
{{~}}
|
||||
|
@ -159,18 +154,7 @@ function (data, dataType, dataPath) {
|
|||
{{?}};
|
||||
|
||||
if (keyMatches) {
|
||||
var _data = data[key]
|
||||
, _dataType = getDataType(_data)
|
||||
, _dataPath = dataPath + '.{{= $propertyKey }}'
|
||||
, result = ({{= it._validate($it) }})(_data, _dataType, _dataPath);
|
||||
|
||||
if (!result.valid) {
|
||||
{{? it.opts.allErrors }}
|
||||
errors.push.apply(errors, result.errors);
|
||||
{{??}}
|
||||
return result;
|
||||
{{?}}
|
||||
}
|
||||
{{# def.validateProperty:'key' }} /* TODO cache data types and paths by keys */
|
||||
}
|
||||
}
|
||||
{{?}}
|
||||
|
|
|
@ -31,17 +31,14 @@ describe.only('JSON-Schema tests', function () {
|
|||
var testSets = require(file.path);
|
||||
testSets.forEach(function (testSet) {
|
||||
// if (testSet.description != 'additionalProperties can exist by itself') return;
|
||||
// describe(testSet.description, function() {
|
||||
it(testSet.description, function() {
|
||||
var validate, fullValidate;
|
||||
// before(function() {
|
||||
validate = jv.compile(testSet.schema);
|
||||
fullValidate = fullJv.compile(testSet.schema);
|
||||
// });
|
||||
describe(testSet.description, function() {
|
||||
// it(testSet.description, function() {
|
||||
var validate = jv.compile(testSet.schema);
|
||||
var fullValidate = fullJv.compile(testSet.schema);
|
||||
|
||||
testSet.tests.forEach(function (test) {
|
||||
// if (test.description != 'a single invalid match is invalid') return;
|
||||
// it(test.description, function() {
|
||||
it(test.description, function() {
|
||||
var result = validate(test.data);
|
||||
// console.log('result', result);
|
||||
assert.equal(result.valid, test.valid);
|
||||
|
@ -53,7 +50,7 @@ describe.only('JSON-Schema tests', function () {
|
|||
assert.equal(result.valid, test.valid);
|
||||
if (result.valid) assert(result.errors.length == 0);
|
||||
else assert(result.errors.length > 0);
|
||||
// });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue