another-json-schema
Advanced tools
Comparing version 3.2.1 to 3.3.0
@@ -0,1 +1,5 @@ | ||
## 3.3.0/2018-01-08 | ||
- add `ignoreNodeType` | ||
## 3.2.1/2017-11-14 | ||
@@ -2,0 +6,0 @@ |
@@ -24,3 +24,5 @@ const helpersFuncs = require('./helpers') | ||
} | ||
if (typeof schema !== 'object') throw new TypeError('Schema must be object or array') | ||
if (typeof schema !== 'object') { | ||
throw new TypeError(`Schema must be object or array, but got ${JSON.stringify(schema)}, maybe missing 'type' validator.`) | ||
} | ||
@@ -113,3 +115,5 @@ this._children = _compileSchema(schema, this) | ||
validateType(children, ctx) | ||
if (!opts.ignoreNodeType) { | ||
validateType(children, ctx) | ||
} | ||
@@ -116,0 +120,0 @@ if (ctx._leaf || !isObject) { |
{ | ||
"name": "another-json-schema", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Another JSON Schema, simple & flexible & intuitive.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -317,2 +317,3 @@ ### another-json-schema | ||
- additionalProperties: {Boolean} if true, retain the original field. default `false` | ||
- ignoreNodeType: {Boolean} if true, ignore check node type, like: `[]`. default: `false` | ||
- gt, gte, lt, lte ...: {Boolean} if false, will not execute this validator. | ||
@@ -319,0 +320,0 @@ |
@@ -9,3 +9,3 @@ const AJS = require('..') | ||
} catch (e) { | ||
assert.equal(e.message, 'Schema must be object or array') | ||
assert.ok(e.message.match(/Schema must be object or array/)) | ||
} | ||
@@ -12,0 +12,0 @@ }) |
@@ -56,2 +56,42 @@ const AJS = require('..') | ||
it('ignoreNodeType', function () { | ||
let userSchema = AJS('userSchema', { | ||
posts: [{ type: 'string' }] | ||
}) | ||
assert.deepEqual(userSchema.validate({ | ||
posts: '1' | ||
}), { | ||
valid: false, | ||
error: { | ||
validator: 'type', | ||
path: '$.posts[]', | ||
actual: '1', | ||
expected: [ { type: 'string' } ], | ||
schema: 'userSchema' | ||
}, | ||
result: { posts: '1' } | ||
}) | ||
assert.deepEqual(userSchema.validate({ | ||
posts: '1' | ||
}, { ignoreNodeType: true }), { | ||
valid: true, | ||
error: null, | ||
result: { posts: '1' } | ||
}) | ||
userSchema = AJS('userSchema', { | ||
posts: { type: 'string' } | ||
}) | ||
assert.deepEqual(userSchema.validate({ | ||
posts: ['1', '2', '3'] | ||
}, { ignoreNodeType: true }), { | ||
valid: true, | ||
error: null, | ||
result: { posts: ['1', '2', '3'] } | ||
}) | ||
}) | ||
it('normal', function () { | ||
@@ -58,0 +98,0 @@ let schema = AJS({ type: 'string' }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44174
1138
357