Socket
Socket
Sign inDemoInstall

ajv

Package Overview
Dependencies
Maintainers
1
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

spec/JSON-Schema-Test-Suite/.npmignore

31

lib/compile/rules/$ref.dot.js

@@ -1,18 +0,13 @@

function (data, dataPath) {
'use strict';
{{? it.resolveRef(it.schema) }}
var result = validateRef('{{= it.schema }}', data, dataPath);
if (!result.valid) validate.errors.push.apply(validate.errors, result.errors);
return result.valid;
{{??}}
validate.errors.push({
keyword: '$ref',
dataPath: dataPath,
message: 'can\'t resolve reference {{= it.schema}}'
{{? it.opts.verbose }}, schema: '{{= it.schema }}', data: data{{?}}
});
return false;
{{?}}
}
{{? it.resolveRef(it.schema.$ref) }}
var result = validateRef('{{= it.schema.$ref }}', data, dataPath);
if (!result.valid) validate.errors.push.apply(validate.errors, result.errors);
var valid = result.valid;
{{??}}
validate.errors.push({
keyword: '$ref',
dataPath: dataPath,
message: 'can\'t resolve reference {{= it.schema.$ref}}'
{{? it.opts.verbose }}, schema: '{{= it.schema.$ref }}', data: data{{?}}
});
var valid = false;
{{?}}
function (data, dataPath) {
'use strict';
{{? it.opts.allErrors }} var errs = validate.errors.length; {{?}}

@@ -5,0 +3,0 @@

function (data, dataPath) {
'use strict';
var errs = validate.errors.length;

@@ -5,0 +3,0 @@

function (data, dataPath) {
'use strict';
{{? it.opts.allErrors }} var errs = validate.errors.length; {{?}}

@@ -5,0 +3,0 @@

@@ -1,18 +0,11 @@

function (data, dataPath) {
'use strict';
/* TODO change to inline */
{{ var $itemsHash = it.toHash(it.schema.enum, it.stableStringify); }}
{{ var $itemsHash = it.toHash(it.schema, it.stableStringify); }}
var req_itemsHash = {{= JSON.stringify($itemsHash) }};
var valid = req_itemsHash[stableStringify(data)] || false;
var itemsHash = {{= JSON.stringify($itemsHash) }};
var valid = itemsHash[stableStringify(data)];
if (!valid) validate.errors.push({
keyword: 'enum',
dataPath: dataPath,
message: 'should be equal to one of values'
{{? it.opts.verbose }}, schema: validate.schema{{= it.schemaPath }}, data: data{{?}}
});
return valid || false;
}
if (!valid) validate.errors.push({
keyword: 'enum',
dataPath: dataPath,
message: 'should be equal to one of values'
{{? it.opts.verbose }}, schema: validate.schema{{= it.schemaPath + '.enum' }}, data: data{{?}}
});

@@ -13,9 +13,9 @@ 'use strict';

{ type: 'array',
inline: [ 'maxItems', 'minItems' ],
func: [ 'items', 'uniqueItems' ] },
inline: [ 'maxItems', 'minItems', 'uniqueItems' ],
func: [ 'items' ] },
{ type: 'object',
inline: [ 'maxProperties', 'minProperties', 'required' ],
func: [ 'dependencies', 'properties' ] },
{ inline: [ 'type' ],
func: [ '$ref', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
{ inline: [ '$ref', 'type', 'enum' ],
func: [ 'not', 'anyOf', 'oneOf', 'allOf' ] }
];

@@ -22,0 +22,0 @@

@@ -14,4 +14,2 @@ {{## def.validateItems:startFrom:

function (data, dataPath) {
'use strict';
{{? it.opts.allErrors }} var errs = validate.errors.length; {{?}}

@@ -18,0 +16,0 @@

function (data, dataPath) {
'use strict';
var errs = validate.errors.length;

@@ -5,0 +3,0 @@

function (data, dataPath) {
'use strict';
var foundValid = false

@@ -5,0 +3,0 @@ , errs = validate.errors.length;

@@ -12,9 +12,6 @@ {{## def.validateProperty:useKey:

function (data, dataPath) {
'use strict';
{{? it.opts.allErrors }} var errs = validate.errors.length; {{?}}
var errs = validate.errors.length;
{{
var $propertyKeys = Object.keys(it.schema || {})
, $pProperties = it.parentSchema.patternProperties || {}
var $pProperties = it.parentSchema.patternProperties || {}
, $pPropertyKeys = $pProperties && Object.keys($pProperties)

@@ -103,3 +100,3 @@ , $aProperties = it.parentSchema.additionalProperties

{{~ $propertyKeys:$propertyKey }}
{{ if (it.schema) for (var $propertyKey in it.schema) { }}
{{ var $schema = it.schema[$propertyKey]; }}

@@ -120,3 +117,3 @@

{{?}}
{{~}}
{{ } }}

@@ -123,0 +120,0 @@

@@ -1,6 +0,6 @@

{{ var $req_schema = it.schema.required; }}
{{? $req_schema.length <= 100 }}
var valid = {{~ $req_schema:$req_property:$i }}
{{ var $schema = it.schema.required; }}
{{? $schema.length <= 100 }}
var valid = {{~ $schema:$property:$i }}
{{? $i}} && {{?}}
data.hasOwnProperty('{{= it.escapeQuotes($req_property) }}')
data.hasOwnProperty('{{= it.escapeQuotes($property) }}')
{{~}};

@@ -22,4 +22,4 @@ {{??}}

dataPath: dataPath,
message: 'properties {{= $req_schema.slice(0, 7).join(",") }}{{? $req_schema.length > 7}}...{{?}} are required'
message: 'properties {{= $schema.slice(0, 7).join(",") }}{{? $schema.length > 7}}...{{?}} are required'
{{? it.opts.verbose }}, schema: validate.schema{{= it.schemaPath + '.required' }}, data: data{{?}}
});

@@ -1,16 +0,15 @@

function (data, dataPath) {
'use strict';
{{? it.opts.allErrors }} var errs = validate.errors.length; {{?}}
/* TODO change to inline ??? with break in the loop */
var valid = true;
var errs = validate.errors.length;
{{? it.schema.uniqueItems && it.opts.uniqueItems !== false }}
if (data.length > 1) {
var unique_itemsHash = {};
{{? it.schema && it.opts.uniqueItems !== false }}
if (data.length <= 1) return true;
var itemsHash = {}, errors = [];
for (var i = 0; i < data.length; i++) {
var itemStr = stableStringify(data[i]);
var isDuplicate = itemsHash[itemStr];
if (isDuplicate) {
var valid = valid && !unique_itemsHash[itemStr];
if (valid)
unique_itemsHash[itemStr] = true;
else {
validate.errors.push({

@@ -20,15 +19,9 @@ keyword: 'uniqueItems',

message: 'item #' + i + 'is duplicate'
{{? it.opts.verbose }}, schema: {{= it.schema }}, data: data{{?}}
{{? it.opts.verbose }}, schema: {{= it.schema.uniqueItems }}, data: data{{?}}
});
{{? !it.opts.allErrors }} return false; {{?}}
} else {
itemsHash[itemStr] = true;
{{? !it.opts.allErrors }} break; {{?}}
}
}
return {{? it.opts.allErrors }} errs == validate.errors.length {{??}} true {{?}};
{{??}}
return true;
{{?}}
}
}
{{?}}

@@ -15,8 +15,8 @@ /**

it.isRoot = false;
var out = '\nfunction (data) { \n "use strict"; \n';
var out = '\nfunction (data) { \n';
out += 'var dataPath = ""; \n';
out += 'var errs = validate.errors.length = 0; \n';
out += (it.opts.allErrors ? 'var errs = ' : '') + 'validate.errors.length = 0; \n';
} else {
var out = '\nfunction (data, dataPath) { \n "use strict"; \n';
out += 'var errs = validate.errors.length; \n';
var out = '\nfunction (data, dataPath) { \n';
if (it.opts.allErrors) out += 'var errs = validate.errors.length; \n';
}

@@ -23,0 +23,0 @@

{
"name": "ajv",
"version": "0.1.5",
"version": "0.1.6",
"description": "Another JSON schema Validator",

@@ -30,4 +30,5 @@ "main": "lib/ajv.js",

"JSON-Schema-Test-Suite": "git+ssh://git@github.com/json-schema/JSON-Schema-Test-Suite.git",
"glob": "^5.0.10",
"mocha": "^2.2.5"
}
}
'use strict';
var fs = require('fs')
var glob = require('glob')
, path = require('path')
, assert = require('assert')
, TESTS_PATH = 'JSON-Schema-Test-Suite/tests/draft4/';
, assert = require('assert');

@@ -23,4 +22,4 @@ var ONLY_RULES, SKIP_RULES;

SKIP_RULES = [
// 'refRemote',
// 'optional/zeroTerminatedFloats'
'refRemote',
'optional/zeroTerminatedFloats'
];

@@ -34,5 +33,5 @@

var remoteRefs = {
'http://localhost:1234/integer.json': require('../JSON-Schema-Test-Suite/remotes/integer.json'),
'http://localhost:1234/subSchemas.json': require('../JSON-Schema-Test-Suite/remotes/subSchemas.json'),
'http://localhost:1234/folder/folderInteger.json': require('../JSON-Schema-Test-Suite/remotes/folder/folderInteger.json')
'http://localhost:1234/integer.json': require('./JSON-Schema-Test-Suite/remotes/integer.json'),
'http://localhost:1234/subSchemas.json': require('./JSON-Schema-Test-Suite/remotes/subSchemas.json'),
'http://localhost:1234/folder/folderInteger.json': require('./JSON-Schema-Test-Suite/remotes/folder/folderInteger.json')
};

@@ -47,32 +46,37 @@

describe('JSON-Schema tests', function () {
var testsPath = path.join(__dirname, '..', TESTS_PATH);
var files = getTestFilesRecursive(testsPath);
addTests('draft4: ', './json-schema-test-suite/tests/draft4/{**/,}*.json');
files.forEach(function (file) {
if (ONLY_RULES && ONLY_RULES.indexOf(file.name) == -1) return;
if (SKIP_RULES && SKIP_RULES.indexOf(file.name) >= 0) return;
function addTests(description, testsPath) {
describe(description, function() {
var files = getTestFiles(testsPath);
describe(file.name, function() {
var testSets = require(file.path);
testSets.forEach(function (testSet) {
// if (testSet.description != 'multiple types can be specified in an array') return;
describe(testSet.description, function() {
// it(testSet.description, function() {
var validate = ajv.compile(testSet.schema);
var fullValidate = fullAjv.compile(testSet.schema);
files.forEach(function (file) {
if (ONLY_RULES && ONLY_RULES.indexOf(file.name) == -1) return;
if (SKIP_RULES && SKIP_RULES.indexOf(file.name) >= 0) return;
testSet.tests.forEach(function (test) {
// if (test.description != 'an integer is valid') return;
it(test.description, function() {
var valid = validate(test.data);
// console.log('result', result);
assert.equal(valid, test.valid);
if (valid) assert(validate.errors.length == 0);
else assert(validate.errors.length > 0);
describe(file.name, function() {
var testSets = require(file.path);
testSets.forEach(function (testSet) {
// if (testSet.description != 'multiple types can be specified in an array') return;
describe(testSet.description, function() {
// it(testSet.description, function() {
var validate = ajv.compile(testSet.schema);
var fullValidate = fullAjv.compile(testSet.schema);
var valid = fullValidate(test.data);
// console.log('full result', result);
assert.equal(valid, test.valid);
if (valid) assert(validate.errors.length == 0);
else assert(validate.errors.length > 0);
testSet.tests.forEach(function (test) {
// if (test.description != 'an integer is valid') return;
it(test.description, function() {
var valid = validate(test.data);
// console.log('result', result);
assert.equal(valid, test.valid);
if (valid) assert(validate.errors.length == 0);
else assert(validate.errors.length > 0);
var valid = fullValidate(test.data);
// console.log('full result', result);
assert.equal(valid, test.valid);
if (valid) assert(validate.errors.length == 0);
else assert(validate.errors.length > 0);
});
});
});

@@ -83,21 +87,12 @@ });

});
});
}
});
function getTestFilesRecursive(rootPath) {
var list = fs.readdirSync(rootPath);
var files = [];
list.forEach(function (item) {
var itemPath = path.join(rootPath, item);
var stat = fs.statSync(itemPath);
if (stat.isFile()) files.push({ name: path.basename(item, '.json'), path: itemPath });
else if (stat.isDirectory()) {
var _files = getTestFilesRecursive(itemPath);
_files.forEach(function (f) {
files.push({ name: path.join(item, f.name), path: f.path })
});
}
function getTestFiles(testsPath) {
var files = glob.sync(testsPath, { cwd: __dirname });
return files.map(function (file) {
var optional = /optional\/\w+\.json/.test(file) ? 'optional/' : '';
return { path: file, name: optional + path.basename(file, '.json') };
});
return files;
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc