Template Upload
This commit is contained in:
2
node_modules/is-my-json-valid/.npmignore
generated
vendored
Normal file
2
node_modules/is-my-json-valid/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
cosmicrealms.com
|
3
node_modules/is-my-json-valid/.travis.yml
generated
vendored
Normal file
3
node_modules/is-my-json-valid/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
21
node_modules/is-my-json-valid/LICENSE
generated
vendored
Normal file
21
node_modules/is-my-json-valid/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Mathias Buus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
200
node_modules/is-my-json-valid/README.md
generated
vendored
Normal file
200
node_modules/is-my-json-valid/README.md
generated
vendored
Normal file
@ -0,0 +1,200 @@
|
||||
# is-my-json-valid
|
||||
|
||||
A [JSONSchema](http://json-schema.org/) validator that uses code generation
|
||||
to be extremely fast
|
||||
|
||||
```
|
||||
npm install is-my-json-valid
|
||||
```
|
||||
|
||||
It passes the entire JSONSchema v4 test suite except for `remoteRefs` and `maxLength`/`minLength` when using unicode surrogate pairs.
|
||||
|
||||
[](http://travis-ci.org/mafintosh/is-my-json-valid)
|
||||
|
||||
## Usage
|
||||
|
||||
Simply pass a schema to compile it
|
||||
|
||||
``` js
|
||||
var validator = require('is-my-json-valid')
|
||||
|
||||
var validate = validator({
|
||||
required: true,
|
||||
type: 'object',
|
||||
properties: {
|
||||
hello: {
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log('should be valid', validate({hello: 'world'}))
|
||||
console.log('should not be valid', validate({}))
|
||||
|
||||
// get the last list of errors by checking validate.errors
|
||||
// the following will print [{field: 'data.hello', message: 'is required'}]
|
||||
console.log(validate.errors)
|
||||
```
|
||||
|
||||
You can also pass the schema as a string
|
||||
|
||||
``` js
|
||||
var validate = validator('{"type": ... }')
|
||||
```
|
||||
|
||||
Optionally you can use the require submodule to load a schema from `__dirname`
|
||||
|
||||
``` js
|
||||
var validator = require('is-my-json-valid/require')
|
||||
var validate = validator('my-schema.json')
|
||||
```
|
||||
|
||||
## Custom formats
|
||||
|
||||
is-my-json-valid supports the formats specified in JSON schema v4 (such as date-time).
|
||||
If you want to add your own custom formats pass them as the formats options to the validator
|
||||
|
||||
``` js
|
||||
var validate = validator({
|
||||
type: 'string',
|
||||
required: true,
|
||||
format: 'only-a'
|
||||
}, {
|
||||
formats: {
|
||||
'only-a': /^a+$/
|
||||
}
|
||||
})
|
||||
|
||||
console.log(validate('aa')) // true
|
||||
console.log(validate('ab')) // false
|
||||
```
|
||||
|
||||
## External schemas
|
||||
|
||||
You can pass in external schemas that you reference using the `$ref` attribute as the `schemas` option
|
||||
|
||||
``` js
|
||||
var ext = {
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
|
||||
var schema = {
|
||||
$ref: '#ext' // references another schema called ext
|
||||
}
|
||||
|
||||
// pass the external schemas as an option
|
||||
var validate = validator(schema, {schemas: {ext: ext}})
|
||||
|
||||
validate('hello') // returns true
|
||||
validate(42) // return false
|
||||
```
|
||||
|
||||
## Filtering away additional properties
|
||||
|
||||
is-my-json-valid supports filtering away properties not in the schema
|
||||
|
||||
``` js
|
||||
var filter = validator.filter({
|
||||
required: true,
|
||||
type: 'object',
|
||||
properties: {
|
||||
hello: {type: 'string', required: true}
|
||||
},
|
||||
additionalProperties: false
|
||||
})
|
||||
|
||||
var doc = {hello: 'world', notInSchema: true}
|
||||
console.log(filter(doc)) // {hello: 'world'}
|
||||
```
|
||||
|
||||
## Verbose mode outputs the value on errors
|
||||
|
||||
is-my-json-valid outputs the value causing an error when verbose is set to true
|
||||
|
||||
``` js
|
||||
var validate = validator({
|
||||
required: true,
|
||||
type: 'object',
|
||||
properties: {
|
||||
hello: {
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
verbose: true
|
||||
})
|
||||
|
||||
validate({hello: 100});
|
||||
console.log(validate.errors) // {field: 'data.hello', message: 'is the wrong type', value: 100, type: 'string'}
|
||||
```
|
||||
|
||||
## Greedy mode tries to validate as much as possible
|
||||
|
||||
By default is-my-json-valid bails on first validation error but when greedy is
|
||||
set to true it tries to validate as much as possible:
|
||||
|
||||
``` js
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
x: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
required: ['x', 'y']
|
||||
}, {
|
||||
greedy: true
|
||||
});
|
||||
|
||||
validate({x: 'string'});
|
||||
console.log(validate.errors) // [{field: 'data.y', message: 'is required'},
|
||||
// {field: 'data.x', message: 'is the wrong type'}]
|
||||
```
|
||||
|
||||
## Error messages
|
||||
|
||||
Here is a list of possible `message` values for errors:
|
||||
|
||||
* `is required`
|
||||
* `is the wrong type`
|
||||
* `has additional items`
|
||||
* `must be FORMAT format` (FORMAT is the `format` property from the schema)
|
||||
* `must be unique`
|
||||
* `must be an enum value`
|
||||
* `dependencies not set`
|
||||
* `has additional properties`
|
||||
* `referenced schema does not match`
|
||||
* `negative schema matches`
|
||||
* `pattern mismatch`
|
||||
* `no schemas match`
|
||||
* `no (or more than one) schemas match`
|
||||
* `has a remainder`
|
||||
* `has more properties than allowed`
|
||||
* `has less properties than allowed`
|
||||
* `has more items than allowed`
|
||||
* `has less items than allowed`
|
||||
* `has longer length than allowed`
|
||||
* `has less length than allowed`
|
||||
* `is less than minimum`
|
||||
* `is more than maximum`
|
||||
|
||||
## Performance
|
||||
|
||||
is-my-json-valid uses code generation to turn your JSON schema into basic javascript code that is easily optimizeable by v8.
|
||||
|
||||
At the time of writing, is-my-json-valid is the __fastest validator__ when running
|
||||
|
||||
* [json-schema-benchmark](https://github.com/Muscula/json-schema-benchmark)
|
||||
* [cosmicreals.com benchmark](http://cosmicrealms.com/blog/2014/08/29/benchmark-of-node-dot-js-json-validation-modules-part-3/)
|
||||
* [jsck benchmark](https://github.com/pandastrike/jsck/issues/72#issuecomment-70992684)
|
||||
* [themis benchmark](https://cdn.rawgit.com/playlyfe/themis/master/benchmark/results.html)
|
||||
* [z-schema benchmark](https://rawgit.com/zaggino/z-schema/master/benchmark/results.html)
|
||||
|
||||
If you know any other relevant benchmarks open a PR and I'll add them.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
18
node_modules/is-my-json-valid/example.js
generated
vendored
Normal file
18
node_modules/is-my-json-valid/example.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
var validator = require('./')
|
||||
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
hello: {
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
console.log('should be valid', validate({hello: 'world'}))
|
||||
console.log('should not be valid', validate({}))
|
||||
|
||||
// get the last error message by checking validate.error
|
||||
// the following will print "data.hello is required"
|
||||
console.log('the errors were:', validate.errors)
|
14
node_modules/is-my-json-valid/formats.js
generated
vendored
Normal file
14
node_modules/is-my-json-valid/formats.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
exports['date-time'] = /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}[tT ]\d{2}:\d{2}:\d{2}(\.\d+)?([zZ]|[+-]\d{2}:\d{2})$/
|
||||
exports['date'] = /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/
|
||||
exports['time'] = /^\d{2}:\d{2}:\d{2}$/
|
||||
exports['email'] = /^\S+@\S+$/
|
||||
exports['ip-address'] = exports['ipv4'] = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
||||
exports['ipv6'] = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/
|
||||
exports['uri'] = /^[a-zA-Z][a-zA-Z0-9+-.]*:[^\s]*$/
|
||||
exports['color'] = /(#?([0-9A-Fa-f]{3,6})\b)|(aqua)|(black)|(blue)|(fuchsia)|(gray)|(green)|(lime)|(maroon)|(navy)|(olive)|(orange)|(purple)|(red)|(silver)|(teal)|(white)|(yellow)|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\))/
|
||||
exports['hostname'] = /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/
|
||||
exports['alpha'] = /^[a-zA-Z]+$/
|
||||
exports['alphanumeric'] = /^[a-zA-Z0-9]+$/
|
||||
exports['style'] = /\s*(.+?):\s*([^;]+);?/g
|
||||
exports['phone'] = /^\+(?:[0-9] ?){6,14}[0-9]$/
|
||||
exports['utc-millisec'] = /^[0-9]{1,15}\.?[0-9]{0,15}$/
|
590
node_modules/is-my-json-valid/index.js
generated
vendored
Normal file
590
node_modules/is-my-json-valid/index.js
generated
vendored
Normal file
@ -0,0 +1,590 @@
|
||||
var genobj = require('generate-object-property')
|
||||
var genfun = require('generate-function')
|
||||
var jsonpointer = require('jsonpointer')
|
||||
var xtend = require('xtend')
|
||||
var formats = require('./formats')
|
||||
|
||||
var get = function(obj, additionalSchemas, ptr) {
|
||||
|
||||
var visit = function(sub) {
|
||||
if (sub && sub.id === ptr) return sub
|
||||
if (typeof sub !== 'object' || !sub) return null
|
||||
return Object.keys(sub).reduce(function(res, k) {
|
||||
return res || visit(sub[k])
|
||||
}, null)
|
||||
}
|
||||
|
||||
var res = visit(obj)
|
||||
if (res) return res
|
||||
|
||||
ptr = ptr.replace(/^#/, '')
|
||||
ptr = ptr.replace(/\/$/, '')
|
||||
|
||||
try {
|
||||
return jsonpointer.get(obj, decodeURI(ptr))
|
||||
} catch (err) {
|
||||
var end = ptr.indexOf('#')
|
||||
var other
|
||||
// external reference
|
||||
if (end !== 0) {
|
||||
// fragment doesn't exist.
|
||||
if (end === -1) {
|
||||
other = additionalSchemas[ptr]
|
||||
} else {
|
||||
var ext = ptr.slice(0, end)
|
||||
other = additionalSchemas[ext]
|
||||
var fragment = ptr.slice(end).replace(/^#/, '')
|
||||
try {
|
||||
return jsonpointer.get(other, fragment)
|
||||
} catch (err) {}
|
||||
}
|
||||
} else {
|
||||
other = additionalSchemas[ptr]
|
||||
}
|
||||
return other || null
|
||||
}
|
||||
}
|
||||
|
||||
var formatName = function(field) {
|
||||
field = JSON.stringify(field)
|
||||
var pattern = /\[([^\[\]"]+)\]/
|
||||
while (pattern.test(field)) field = field.replace(pattern, '."+$1+"')
|
||||
return field
|
||||
}
|
||||
|
||||
var types = {}
|
||||
|
||||
types.any = function() {
|
||||
return 'true'
|
||||
}
|
||||
|
||||
types.null = function(name) {
|
||||
return name+' === null'
|
||||
}
|
||||
|
||||
types.boolean = function(name) {
|
||||
return 'typeof '+name+' === "boolean"'
|
||||
}
|
||||
|
||||
types.array = function(name) {
|
||||
return 'Array.isArray('+name+')'
|
||||
}
|
||||
|
||||
types.object = function(name) {
|
||||
return 'typeof '+name+' === "object" && '+name+' && !Array.isArray('+name+')'
|
||||
}
|
||||
|
||||
types.number = function(name) {
|
||||
return 'typeof '+name+' === "number"'
|
||||
}
|
||||
|
||||
types.integer = function(name) {
|
||||
return 'typeof '+name+' === "number" && (Math.floor('+name+') === '+name+' || '+name+' > 9007199254740992 || '+name+' < -9007199254740992)'
|
||||
}
|
||||
|
||||
types.string = function(name) {
|
||||
return 'typeof '+name+' === "string"'
|
||||
}
|
||||
|
||||
var unique = function(array) {
|
||||
var list = []
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
list.push(typeof array[i] === 'object' ? JSON.stringify(array[i]) : array[i])
|
||||
}
|
||||
for (var i = 1; i < list.length; i++) {
|
||||
if (list.indexOf(list[i]) !== i) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var isMultipleOf = function(name, multipleOf) {
|
||||
var res;
|
||||
var factor = ((multipleOf | 0) !== multipleOf) ? Math.pow(10, multipleOf.toString().split('.').pop().length) : 1
|
||||
if (factor > 1) {
|
||||
var factorName = ((name | 0) !== name) ? Math.pow(10, name.toString().split('.').pop().length) : 1
|
||||
if (factorName > factor) res = true
|
||||
else res = Math.round(factor * name) % (factor * multipleOf)
|
||||
}
|
||||
else res = name % multipleOf;
|
||||
return !res;
|
||||
}
|
||||
|
||||
var compile = function(schema, cache, root, reporter, opts) {
|
||||
var fmts = opts ? xtend(formats, opts.formats) : formats
|
||||
var scope = {unique:unique, formats:fmts, isMultipleOf:isMultipleOf}
|
||||
var verbose = opts ? !!opts.verbose : false;
|
||||
var greedy = opts && opts.greedy !== undefined ?
|
||||
opts.greedy : false;
|
||||
|
||||
var syms = {}
|
||||
var gensym = function(name) {
|
||||
return name+(syms[name] = (syms[name] || 0)+1)
|
||||
}
|
||||
|
||||
var reversePatterns = {}
|
||||
var patterns = function(p) {
|
||||
if (reversePatterns[p]) return reversePatterns[p]
|
||||
var n = gensym('pattern')
|
||||
scope[n] = new RegExp(p)
|
||||
reversePatterns[p] = n
|
||||
return n
|
||||
}
|
||||
|
||||
var vars = ['i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z']
|
||||
var genloop = function() {
|
||||
var v = vars.shift()
|
||||
vars.push(v+v[0])
|
||||
return v
|
||||
}
|
||||
|
||||
var visit = function(name, node, reporter, filter) {
|
||||
var properties = node.properties
|
||||
var type = node.type
|
||||
var tuple = false
|
||||
|
||||
if (Array.isArray(node.items)) { // tuple type
|
||||
properties = {}
|
||||
node.items.forEach(function(item, i) {
|
||||
properties[i] = item
|
||||
})
|
||||
type = 'array'
|
||||
tuple = true
|
||||
}
|
||||
|
||||
var indent = 0
|
||||
var error = function(msg, prop, value) {
|
||||
validate('errors++')
|
||||
if (reporter === true) {
|
||||
validate('if (validate.errors === null) validate.errors = []')
|
||||
if (verbose) {
|
||||
validate('validate.errors.push({field:%s,message:%s,value:%s,type:%s})', formatName(prop || name), JSON.stringify(msg), value || name, JSON.stringify(type))
|
||||
} else {
|
||||
validate('validate.errors.push({field:%s,message:%s})', formatName(prop || name), JSON.stringify(msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (node.required === true) {
|
||||
indent++
|
||||
validate('if (%s === undefined) {', name)
|
||||
error('is required')
|
||||
validate('} else {')
|
||||
} else {
|
||||
indent++
|
||||
validate('if (%s !== undefined) {', name)
|
||||
}
|
||||
|
||||
var valid = [].concat(type)
|
||||
.map(function(t) {
|
||||
if (t && !types.hasOwnProperty(t)) {
|
||||
throw new Error('Unknown type: ' + t)
|
||||
}
|
||||
|
||||
return types[t || 'any'](name)
|
||||
})
|
||||
.join(' || ') || 'true'
|
||||
|
||||
if (valid !== 'true') {
|
||||
indent++
|
||||
validate('if (!(%s)) {', valid)
|
||||
error('is the wrong type')
|
||||
validate('} else {')
|
||||
}
|
||||
|
||||
if (tuple) {
|
||||
if (node.additionalItems === false) {
|
||||
validate('if (%s.length > %d) {', name, node.items.length)
|
||||
error('has additional items')
|
||||
validate('}')
|
||||
} else if (node.additionalItems) {
|
||||
var i = genloop()
|
||||
validate('for (var %s = %d; %s < %s.length; %s++) {', i, node.items.length, i, name, i)
|
||||
visit(name+'['+i+']', node.additionalItems, reporter, filter)
|
||||
validate('}')
|
||||
}
|
||||
}
|
||||
|
||||
if (node.format && fmts[node.format]) {
|
||||
if (type !== 'string' && formats[node.format]) validate('if (%s) {', types.string(name))
|
||||
var n = gensym('format')
|
||||
scope[n] = fmts[node.format]
|
||||
|
||||
if (typeof scope[n] === 'function') validate('if (!%s(%s)) {', n, name)
|
||||
else validate('if (!%s.test(%s)) {', n, name)
|
||||
error('must be '+node.format+' format')
|
||||
validate('}')
|
||||
if (type !== 'string' && formats[node.format]) validate('}')
|
||||
}
|
||||
|
||||
if (Array.isArray(node.required)) {
|
||||
var checkRequired = function (req) {
|
||||
var prop = genobj(name, req);
|
||||
validate('if (%s === undefined) {', prop)
|
||||
error('is required', prop)
|
||||
validate('missing++')
|
||||
validate('}')
|
||||
}
|
||||
validate('if ((%s)) {', type !== 'object' ? types.object(name) : 'true')
|
||||
validate('var missing = 0')
|
||||
node.required.map(checkRequired)
|
||||
validate('}');
|
||||
if (!greedy) {
|
||||
validate('if (missing === 0) {')
|
||||
indent++
|
||||
}
|
||||
}
|
||||
|
||||
if (node.uniqueItems) {
|
||||
if (type !== 'array') validate('if (%s) {', types.array(name))
|
||||
validate('if (!(unique(%s))) {', name)
|
||||
error('must be unique')
|
||||
validate('}')
|
||||
if (type !== 'array') validate('}')
|
||||
}
|
||||
|
||||
if (node.enum) {
|
||||
var complex = node.enum.some(function(e) {
|
||||
return typeof e === 'object'
|
||||
})
|
||||
|
||||
var compare = complex ?
|
||||
function(e) {
|
||||
return 'JSON.stringify('+name+')'+' !== JSON.stringify('+JSON.stringify(e)+')'
|
||||
} :
|
||||
function(e) {
|
||||
return name+' !== '+JSON.stringify(e)
|
||||
}
|
||||
|
||||
validate('if (%s) {', node.enum.map(compare).join(' && ') || 'false')
|
||||
error('must be an enum value')
|
||||
validate('}')
|
||||
}
|
||||
|
||||
if (node.dependencies) {
|
||||
if (type !== 'object') validate('if (%s) {', types.object(name))
|
||||
|
||||
Object.keys(node.dependencies).forEach(function(key) {
|
||||
var deps = node.dependencies[key]
|
||||
if (typeof deps === 'string') deps = [deps]
|
||||
|
||||
var exists = function(k) {
|
||||
return genobj(name, k) + ' !== undefined'
|
||||
}
|
||||
|
||||
if (Array.isArray(deps)) {
|
||||
validate('if (%s !== undefined && !(%s)) {', genobj(name, key), deps.map(exists).join(' && ') || 'true')
|
||||
error('dependencies not set')
|
||||
validate('}')
|
||||
}
|
||||
if (typeof deps === 'object') {
|
||||
validate('if (%s !== undefined) {', genobj(name, key))
|
||||
visit(name, deps, reporter, filter)
|
||||
validate('}')
|
||||
}
|
||||
})
|
||||
|
||||
if (type !== 'object') validate('}')
|
||||
}
|
||||
|
||||
if (node.additionalProperties || node.additionalProperties === false) {
|
||||
if (type !== 'object') validate('if (%s) {', types.object(name))
|
||||
|
||||
var i = genloop()
|
||||
var keys = gensym('keys')
|
||||
|
||||
var toCompare = function(p) {
|
||||
return keys+'['+i+'] !== '+JSON.stringify(p)
|
||||
}
|
||||
|
||||
var toTest = function(p) {
|
||||
return '!'+patterns(p)+'.test('+keys+'['+i+'])'
|
||||
}
|
||||
|
||||
var additionalProp = Object.keys(properties || {}).map(toCompare)
|
||||
.concat(Object.keys(node.patternProperties || {}).map(toTest))
|
||||
.join(' && ') || 'true'
|
||||
|
||||
validate('var %s = Object.keys(%s)', keys, name)
|
||||
('for (var %s = 0; %s < %s.length; %s++) {', i, i, keys, i)
|
||||
('if (%s) {', additionalProp)
|
||||
|
||||
if (node.additionalProperties === false) {
|
||||
if (filter) validate('delete %s', name+'['+keys+'['+i+']]')
|
||||
error('has additional properties', null, JSON.stringify(name+'.') + ' + ' + keys + '['+i+']')
|
||||
} else {
|
||||
visit(name+'['+keys+'['+i+']]', node.additionalProperties, reporter, filter)
|
||||
}
|
||||
|
||||
validate
|
||||
('}')
|
||||
('}')
|
||||
|
||||
if (type !== 'object') validate('}')
|
||||
}
|
||||
|
||||
if (node.$ref) {
|
||||
var sub = get(root, opts && opts.schemas || {}, node.$ref)
|
||||
if (sub) {
|
||||
var fn = cache[node.$ref]
|
||||
if (!fn) {
|
||||
cache[node.$ref] = function proxy(data) {
|
||||
return fn(data)
|
||||
}
|
||||
fn = compile(sub, cache, root, false, opts)
|
||||
}
|
||||
var n = gensym('ref')
|
||||
scope[n] = fn
|
||||
validate('if (!(%s(%s))) {', n, name)
|
||||
error('referenced schema does not match')
|
||||
validate('}')
|
||||
}
|
||||
}
|
||||
|
||||
if (node.not) {
|
||||
var prev = gensym('prev')
|
||||
validate('var %s = errors', prev)
|
||||
visit(name, node.not, false, filter)
|
||||
validate('if (%s === errors) {', prev)
|
||||
error('negative schema matches')
|
||||
validate('} else {')
|
||||
('errors = %s', prev)
|
||||
('}')
|
||||
}
|
||||
|
||||
if (node.items && !tuple) {
|
||||
if (type !== 'array') validate('if (%s) {', types.array(name))
|
||||
|
||||
var i = genloop()
|
||||
validate('for (var %s = 0; %s < %s.length; %s++) {', i, i, name, i)
|
||||
visit(name+'['+i+']', node.items, reporter, filter)
|
||||
validate('}')
|
||||
|
||||
if (type !== 'array') validate('}')
|
||||
}
|
||||
|
||||
if (node.patternProperties) {
|
||||
if (type !== 'object') validate('if (%s) {', types.object(name))
|
||||
var keys = gensym('keys')
|
||||
var i = genloop()
|
||||
validate
|
||||
('var %s = Object.keys(%s)', keys, name)
|
||||
('for (var %s = 0; %s < %s.length; %s++) {', i, i, keys, i)
|
||||
|
||||
Object.keys(node.patternProperties).forEach(function(key) {
|
||||
var p = patterns(key)
|
||||
validate('if (%s.test(%s)) {', p, keys+'['+i+']')
|
||||
visit(name+'['+keys+'['+i+']]', node.patternProperties[key], reporter, filter)
|
||||
validate('}')
|
||||
})
|
||||
|
||||
validate('}')
|
||||
if (type !== 'object') validate('}')
|
||||
}
|
||||
|
||||
if (node.pattern) {
|
||||
var p = patterns(node.pattern)
|
||||
if (type !== 'string') validate('if (%s) {', types.string(name))
|
||||
validate('if (!(%s.test(%s))) {', p, name)
|
||||
error('pattern mismatch')
|
||||
validate('}')
|
||||
if (type !== 'string') validate('}')
|
||||
}
|
||||
|
||||
if (node.allOf) {
|
||||
node.allOf.forEach(function(sch) {
|
||||
visit(name, sch, reporter, filter)
|
||||
})
|
||||
}
|
||||
|
||||
if (node.anyOf && node.anyOf.length) {
|
||||
var prev = gensym('prev')
|
||||
|
||||
node.anyOf.forEach(function(sch, i) {
|
||||
if (i === 0) {
|
||||
validate('var %s = errors', prev)
|
||||
} else {
|
||||
validate('if (errors !== %s) {', prev)
|
||||
('errors = %s', prev)
|
||||
}
|
||||
visit(name, sch, false, false)
|
||||
})
|
||||
node.anyOf.forEach(function(sch, i) {
|
||||
if (i) validate('}')
|
||||
})
|
||||
validate('if (%s !== errors) {', prev)
|
||||
error('no schemas match')
|
||||
validate('}')
|
||||
}
|
||||
|
||||
if (node.oneOf && node.oneOf.length) {
|
||||
var prev = gensym('prev')
|
||||
var passes = gensym('passes')
|
||||
|
||||
validate
|
||||
('var %s = errors', prev)
|
||||
('var %s = 0', passes)
|
||||
|
||||
node.oneOf.forEach(function(sch, i) {
|
||||
visit(name, sch, false, false)
|
||||
validate('if (%s === errors) {', prev)
|
||||
('%s++', passes)
|
||||
('} else {')
|
||||
('errors = %s', prev)
|
||||
('}')
|
||||
})
|
||||
|
||||
validate('if (%s !== 1) {', passes)
|
||||
error('no (or more than one) schemas match')
|
||||
validate('}')
|
||||
}
|
||||
|
||||
if (node.multipleOf !== undefined) {
|
||||
if (type !== 'number' && type !== 'integer') validate('if (%s) {', types.number(name))
|
||||
|
||||
validate('if (!isMultipleOf(%s, %d)) {', name, node.multipleOf)
|
||||
|
||||
error('has a remainder')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'number' && type !== 'integer') validate('}')
|
||||
}
|
||||
|
||||
if (node.maxProperties !== undefined) {
|
||||
if (type !== 'object') validate('if (%s) {', types.object(name))
|
||||
|
||||
validate('if (Object.keys(%s).length > %d) {', name, node.maxProperties)
|
||||
error('has more properties than allowed')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'object') validate('}')
|
||||
}
|
||||
|
||||
if (node.minProperties !== undefined) {
|
||||
if (type !== 'object') validate('if (%s) {', types.object(name))
|
||||
|
||||
validate('if (Object.keys(%s).length < %d) {', name, node.minProperties)
|
||||
error('has less properties than allowed')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'object') validate('}')
|
||||
}
|
||||
|
||||
if (node.maxItems !== undefined) {
|
||||
if (type !== 'array') validate('if (%s) {', types.array(name))
|
||||
|
||||
validate('if (%s.length > %d) {', name, node.maxItems)
|
||||
error('has more items than allowed')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'array') validate('}')
|
||||
}
|
||||
|
||||
if (node.minItems !== undefined) {
|
||||
if (type !== 'array') validate('if (%s) {', types.array(name))
|
||||
|
||||
validate('if (%s.length < %d) {', name, node.minItems)
|
||||
error('has less items than allowed')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'array') validate('}')
|
||||
}
|
||||
|
||||
if (node.maxLength !== undefined) {
|
||||
if (type !== 'string') validate('if (%s) {', types.string(name))
|
||||
|
||||
validate('if (%s.length > %d) {', name, node.maxLength)
|
||||
error('has longer length than allowed')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'string') validate('}')
|
||||
}
|
||||
|
||||
if (node.minLength !== undefined) {
|
||||
if (type !== 'string') validate('if (%s) {', types.string(name))
|
||||
|
||||
validate('if (%s.length < %d) {', name, node.minLength)
|
||||
error('has less length than allowed')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'string') validate('}')
|
||||
}
|
||||
|
||||
if (node.minimum !== undefined) {
|
||||
if (type !== 'number' && type !== 'integer') validate('if (%s) {', types.number(name))
|
||||
|
||||
validate('if (%s %s %d) {', name, node.exclusiveMinimum ? '<=' : '<', node.minimum)
|
||||
error('is less than minimum')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'number' && type !== 'integer') validate('}')
|
||||
}
|
||||
|
||||
if (node.maximum !== undefined) {
|
||||
if (type !== 'number' && type !== 'integer') validate('if (%s) {', types.number(name))
|
||||
|
||||
validate('if (%s %s %d) {', name, node.exclusiveMaximum ? '>=' : '>', node.maximum)
|
||||
error('is more than maximum')
|
||||
validate('}')
|
||||
|
||||
if (type !== 'number' && type !== 'integer') validate('}')
|
||||
}
|
||||
|
||||
if (properties) {
|
||||
Object.keys(properties).forEach(function(p) {
|
||||
if (Array.isArray(type) && type.indexOf('null') !== -1) validate('if (%s !== null) {', name)
|
||||
|
||||
visit(genobj(name, p), properties[p], reporter, filter)
|
||||
|
||||
if (Array.isArray(type) && type.indexOf('null') !== -1) validate('}')
|
||||
})
|
||||
}
|
||||
|
||||
while (indent--) validate('}')
|
||||
}
|
||||
|
||||
var validate = genfun
|
||||
('function validate(data) {')
|
||||
// Since undefined is not a valid JSON value, we coerce to null and other checks will catch this
|
||||
('if (data === undefined) data = null')
|
||||
('validate.errors = null')
|
||||
('var errors = 0')
|
||||
|
||||
visit('data', schema, reporter, opts && opts.filter)
|
||||
|
||||
validate
|
||||
('return errors === 0')
|
||||
('}')
|
||||
|
||||
validate = validate.toFunction(scope)
|
||||
validate.errors = null
|
||||
|
||||
if (Object.defineProperty) {
|
||||
Object.defineProperty(validate, 'error', {
|
||||
get: function() {
|
||||
if (!validate.errors) return ''
|
||||
return validate.errors.map(function(err) {
|
||||
return err.field + ' ' + err.message;
|
||||
}).join('\n')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
validate.toJSON = function() {
|
||||
return schema
|
||||
}
|
||||
|
||||
return validate
|
||||
}
|
||||
|
||||
module.exports = function(schema, opts) {
|
||||
if (typeof schema === 'string') schema = JSON.parse(schema)
|
||||
return compile(schema, {}, schema, true, opts)
|
||||
}
|
||||
|
||||
module.exports.filter = function(schema, opts) {
|
||||
var validate = module.exports(schema, xtend(opts, {filter: true}))
|
||||
return function(sch) {
|
||||
validate(sch)
|
||||
return sch
|
||||
}
|
||||
}
|
111
node_modules/is-my-json-valid/package.json
generated
vendored
Normal file
111
node_modules/is-my-json-valid/package.json
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"is-my-json-valid@^2.12.4",
|
||||
"C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\har-validator"
|
||||
]
|
||||
],
|
||||
"_from": "is-my-json-valid@>=2.12.4-0 <3.0.0-0",
|
||||
"_id": "is-my-json-valid@2.16.0",
|
||||
"_inCache": true,
|
||||
"_location": "/is-my-json-valid",
|
||||
"_nodeVersion": "7.5.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-12-west.internal.npmjs.com",
|
||||
"tmp": "tmp/is-my-json-valid-2.16.0.tgz_1488122410016_0.7586333625949919"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "linus@folkdatorn.se",
|
||||
"name": "linusu"
|
||||
},
|
||||
"_npmVersion": "4.1.2",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "is-my-json-valid",
|
||||
"raw": "is-my-json-valid@^2.12.4",
|
||||
"rawSpec": "^2.12.4",
|
||||
"scope": null,
|
||||
"spec": ">=2.12.4-0 <3.0.0-0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/har-validator"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz",
|
||||
"_shasum": "f079dd9bfdae65ee2038aae8acbc86ab109e3693",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "is-my-json-valid@^2.12.4",
|
||||
"_where": "C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\har-validator",
|
||||
"author": {
|
||||
"name": "Mathias Buus"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/is-my-json-valid/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"generate-function": "^2.0.0",
|
||||
"generate-object-property": "^1.1.0",
|
||||
"jsonpointer": "^4.0.0",
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"description": "A JSONSchema validator that uses code generation to be extremely fast",
|
||||
"devDependencies": {
|
||||
"tape": "^2.13.4"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "f079dd9bfdae65ee2038aae8acbc86ab109e3693",
|
||||
"tarball": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz"
|
||||
},
|
||||
"gitHead": "01db30a6c968bfa87f2b6e16a905e73172bc6bea",
|
||||
"homepage": "https://github.com/mafintosh/is-my-json-valid",
|
||||
"installable": true,
|
||||
"keywords": [
|
||||
"json",
|
||||
"jsonschema",
|
||||
"orderly",
|
||||
"schema"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "emilbay",
|
||||
"email": "github@tixz.dk"
|
||||
},
|
||||
{
|
||||
"name": "emilbayes",
|
||||
"email": "github@tixz.dk"
|
||||
},
|
||||
{
|
||||
"name": "freeall",
|
||||
"email": "freeall@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "linusu",
|
||||
"email": "linus@folkdatorn.se"
|
||||
},
|
||||
{
|
||||
"name": "mafintosh",
|
||||
"email": "mathiasbuus@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "watson",
|
||||
"email": "w@tson.dk"
|
||||
},
|
||||
{
|
||||
"name": "yoshuawuyts",
|
||||
"email": "i@yoshuawuyts.com"
|
||||
}
|
||||
],
|
||||
"name": "is-my-json-valid",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mafintosh/is-my-json-valid.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
},
|
||||
"version": "2.16.0"
|
||||
}
|
12
node_modules/is-my-json-valid/require.js
generated
vendored
Normal file
12
node_modules/is-my-json-valid/require.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
var compile = require('./')
|
||||
|
||||
delete require.cache[require.resolve(__filename)]
|
||||
|
||||
module.exports = function(file, opts) {
|
||||
file = path.join(path.dirname(module.parent.filename), file)
|
||||
if (!fs.existsSync(file) && fs.existsSync(file+'.schema')) file += '.schema'
|
||||
if (!fs.existsSync(file) && fs.existsSync(file+'.json')) file += '.json'
|
||||
return compile(fs.readFileSync(file, 'utf-8'), opts)
|
||||
}
|
84
node_modules/is-my-json-valid/test/fixtures/cosmic.js
generated
vendored
Normal file
84
node_modules/is-my-json-valid/test/fixtures/cosmic.js
generated
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
exports.valid = {
|
||||
fullName : "John Doe",
|
||||
age : 47,
|
||||
state : "Massachusetts",
|
||||
city : "Boston",
|
||||
zip : 16417,
|
||||
married : false,
|
||||
dozen : 12,
|
||||
dozenOrBakersDozen : 13,
|
||||
favoriteEvenNumber : 14,
|
||||
topThreeFavoriteColors : [ "red", "blue", "green" ],
|
||||
favoriteSingleDigitWholeNumbers : [ 7 ],
|
||||
favoriteFiveLetterWord : "coder",
|
||||
emailAddresses :
|
||||
[
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org",
|
||||
"01234567890@numbers-in-local.net",
|
||||
"&'*+-./=?^_{}~@other-valid-characters-in-local.net",
|
||||
"mixed-1234-in-{+^}-local@sld.net",
|
||||
"a@single-character-in-local.org",
|
||||
"\"quoted\"@sld.com",
|
||||
"\"\\e\\s\\c\\a\\p\\e\\d\"@sld.com",
|
||||
"\"quoted-at-sign@sld.org\"@sld.com",
|
||||
"\"escaped\\\"quote\"@sld.com",
|
||||
"\"back\\slash\"@sld.com",
|
||||
"one-character-third-level@a.example.com",
|
||||
"single-character-in-sld@x.org",
|
||||
"local@dash-in-sld.com",
|
||||
"letters-in-sld@123.com",
|
||||
"one-letter-sld@x.org",
|
||||
"uncommon-tld@sld.museum",
|
||||
"uncommon-tld@sld.travel",
|
||||
"uncommon-tld@sld.mobi",
|
||||
"country-code-tld@sld.uk",
|
||||
"country-code-tld@sld.rw",
|
||||
"local@sld.newTLD",
|
||||
"the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-254-characters-exactly.so-it-should-be-valid.and-im-going-to-add-some-more-words-here.to-increase-the-lenght-blah-blah-blah-blah-bla.org",
|
||||
"the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-three-characters-so-it-is-valid-blah-blah.com",
|
||||
"local@sub.domains.com"
|
||||
],
|
||||
ipAddresses : [ "127.0.0.1", "24.48.64.2", "192.168.1.1", "209.68.44.3", "2.2.2.2" ]
|
||||
}
|
||||
|
||||
exports.invalid = {
|
||||
fullName : null,
|
||||
age : -1,
|
||||
state : 47,
|
||||
city : false,
|
||||
zip : [null],
|
||||
married : "yes",
|
||||
dozen : 50,
|
||||
dozenOrBakersDozen : "over 9000",
|
||||
favoriteEvenNumber : 15,
|
||||
topThreeFavoriteColors : [ "red", 5 ],
|
||||
favoriteSingleDigitWholeNumbers : [ 78, 2, 999 ],
|
||||
favoriteFiveLetterWord : "codernaut",
|
||||
emailAddresses : [],
|
||||
ipAddresses : [ "999.0.099.1", "294.48.64.2346", false, "2221409.64214128.42414.235233", "124124.12412412" ]
|
||||
}
|
||||
|
||||
exports.schema = { // from cosmic thingy
|
||||
name : "test",
|
||||
type : "object",
|
||||
additionalProperties : false,
|
||||
required : ["fullName", "age", "zip", "married", "dozen", "dozenOrBakersDozen", "favoriteEvenNumber", "topThreeFavoriteColors", "favoriteSingleDigitWholeNumbers", "favoriteFiveLetterWord", "emailAddresses", "ipAddresses"],
|
||||
properties :
|
||||
{
|
||||
fullName : { type : "string" },
|
||||
age : { type : "integer", minimum : 0 },
|
||||
optionalItem : { type : "string" },
|
||||
state : { type : "string" },
|
||||
city : { type : "string" },
|
||||
zip : { type : "integer", minimum : 0, maximum : 99999 },
|
||||
married : { type : "boolean" },
|
||||
dozen : { type : "integer", minimum : 12, maximum : 12 },
|
||||
dozenOrBakersDozen : { type : "integer", minimum : 12, maximum : 13 },
|
||||
favoriteEvenNumber : { type : "integer", multipleOf : 2 },
|
||||
topThreeFavoriteColors : { type : "array", minItems : 3, maxItems : 3, uniqueItems : true, items : { type : "string" }},
|
||||
favoriteSingleDigitWholeNumbers : { type : "array", minItems : 1, maxItems : 10, uniqueItems : true, items : { type : "integer", minimum : 0, maximum : 9 }},
|
||||
favoriteFiveLetterWord : { type : "string", minLength : 5, maxLength : 5 },
|
||||
emailAddresses : { type : "array", minItems : 1, uniqueItems : true, items : { type : "string", format : "email" }},
|
||||
ipAddresses : { type : "array", uniqueItems : true, items : { type : "string", format : "ipv4" }},
|
||||
}
|
||||
}
|
82
node_modules/is-my-json-valid/test/json-schema-draft4/additionalItems.json
generated
vendored
Normal file
82
node_modules/is-my-json-valid/test/json-schema-draft4/additionalItems.json
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
[
|
||||
{
|
||||
"description": "additionalItems as schema",
|
||||
"schema": {
|
||||
"items": [{}],
|
||||
"additionalItems": {"type": "integer"}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "additional items match schema",
|
||||
"data": [ null, 2, 3, 4 ],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "additional items do not match schema",
|
||||
"data": [ null, 2, 3, "foo" ],
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "items is schema, no additionalItems",
|
||||
"schema": {
|
||||
"items": {},
|
||||
"additionalItems": false
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "all items match schema",
|
||||
"data": [ 1, 2, 3, 4, 5 ],
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "array of items with no additionalItems",
|
||||
"schema": {
|
||||
"items": [{}, {}, {}],
|
||||
"additionalItems": false
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "no additional items present",
|
||||
"data": [ 1, 2, 3 ],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "additional items are not permitted",
|
||||
"data": [ 1, 2, 3, 4 ],
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "additionalItems as false without items",
|
||||
"schema": {"additionalItems": false},
|
||||
"tests": [
|
||||
{
|
||||
"description":
|
||||
"items defaults to empty schema so everything is valid",
|
||||
"data": [ 1, 2, 3, 4, 5 ],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "ignores non-arrays",
|
||||
"data": {"foo" : "bar"},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "additionalItems are allowed by default",
|
||||
"schema": {"items": [{"type": "integer"}]},
|
||||
"tests": [
|
||||
{
|
||||
"description": "only the first item is validated",
|
||||
"data": [1, "foo", false],
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
88
node_modules/is-my-json-valid/test/json-schema-draft4/additionalProperties.json
generated
vendored
Normal file
88
node_modules/is-my-json-valid/test/json-schema-draft4/additionalProperties.json
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
[
|
||||
{
|
||||
"description":
|
||||
"additionalProperties being false does not allow other properties",
|
||||
"schema": {
|
||||
"properties": {"foo": {}, "bar": {}},
|
||||
"patternProperties": { "^v": {} },
|
||||
"additionalProperties": false
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "no additional properties is valid",
|
||||
"data": {"foo": 1},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an additional property is invalid",
|
||||
"data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-objects",
|
||||
"data": [1, 2, 3],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "patternProperties are not additional properties",
|
||||
"data": {"foo":1, "vroom": 2},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description":
|
||||
"additionalProperties allows a schema which should validate",
|
||||
"schema": {
|
||||
"properties": {"foo": {}, "bar": {}},
|
||||
"additionalProperties": {"type": "boolean"}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "no additional properties is valid",
|
||||
"data": {"foo": 1},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an additional valid property is valid",
|
||||
"data": {"foo" : 1, "bar" : 2, "quux" : true},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an additional invalid property is invalid",
|
||||
"data": {"foo" : 1, "bar" : 2, "quux" : 12},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description":
|
||||
"additionalProperties can exist by itself",
|
||||
"schema": {
|
||||
"additionalProperties": {"type": "boolean"}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "an additional valid property is valid",
|
||||
"data": {"foo" : true},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an additional invalid property is invalid",
|
||||
"data": {"foo" : 1},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "additionalProperties are allowed by default",
|
||||
"schema": {"properties": {"foo": {}, "bar": {}}},
|
||||
"tests": [
|
||||
{
|
||||
"description": "additional properties are allowed",
|
||||
"data": {"foo": 1, "bar": 2, "quux": true},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
112
node_modules/is-my-json-valid/test/json-schema-draft4/allOf.json
generated
vendored
Normal file
112
node_modules/is-my-json-valid/test/json-schema-draft4/allOf.json
generated
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
[
|
||||
{
|
||||
"description": "allOf",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"properties": {
|
||||
"bar": {"type": "integer"}
|
||||
},
|
||||
"required": ["bar"]
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"foo": {"type": "string"}
|
||||
},
|
||||
"required": ["foo"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "allOf",
|
||||
"data": {"foo": "baz", "bar": 2},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "mismatch second",
|
||||
"data": {"foo": "baz"},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "mismatch first",
|
||||
"data": {"bar": 2},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "wrong type",
|
||||
"data": {"foo": "baz", "bar": "quux"},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "allOf with base schema",
|
||||
"schema": {
|
||||
"properties": {"bar": {"type": "integer"}},
|
||||
"required": ["bar"],
|
||||
"allOf" : [
|
||||
{
|
||||
"properties": {
|
||||
"foo": {"type": "string"}
|
||||
},
|
||||
"required": ["foo"]
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"baz": {"type": "null"}
|
||||
},
|
||||
"required": ["baz"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid",
|
||||
"data": {"foo": "quux", "bar": 2, "baz": null},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "mismatch base schema",
|
||||
"data": {"foo": "quux", "baz": null},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "mismatch first allOf",
|
||||
"data": {"bar": 2, "baz": null},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "mismatch second allOf",
|
||||
"data": {"foo": "quux", "bar": 2},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "mismatch both",
|
||||
"data": {"bar": 2},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "allOf simple types",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{"maximum": 30},
|
||||
{"minimum": 20}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid",
|
||||
"data": 25,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "mismatch one",
|
||||
"data": 35,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
68
node_modules/is-my-json-valid/test/json-schema-draft4/anyOf.json
generated
vendored
Normal file
68
node_modules/is-my-json-valid/test/json-schema-draft4/anyOf.json
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
[
|
||||
{
|
||||
"description": "anyOf",
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"minimum": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "first anyOf valid",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "second anyOf valid",
|
||||
"data": 2.5,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "both anyOf valid",
|
||||
"data": 3,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "neither anyOf valid",
|
||||
"data": 1.5,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "anyOf with base schema",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"anyOf" : [
|
||||
{
|
||||
"maxLength": 2
|
||||
},
|
||||
{
|
||||
"minLength": 4
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "mismatch base schema",
|
||||
"data": 3,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "one anyOf valid",
|
||||
"data": "foobar",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "both anyOf invalid",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
107
node_modules/is-my-json-valid/test/json-schema-draft4/bignum.json
generated
vendored
Normal file
107
node_modules/is-my-json-valid/test/json-schema-draft4/bignum.json
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
[
|
||||
{
|
||||
"description": "integer",
|
||||
"schema": {"type": "integer"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a bignum is an integer",
|
||||
"data": 12345678910111213141516171819202122232425262728293031,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "number",
|
||||
"schema": {"type": "number"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a bignum is a number",
|
||||
"data": 98249283749234923498293171823948729348710298301928331,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "integer",
|
||||
"schema": {"type": "integer"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a negative bignum is an integer",
|
||||
"data": -12345678910111213141516171819202122232425262728293031,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "number",
|
||||
"schema": {"type": "number"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a negative bignum is a number",
|
||||
"data": -98249283749234923498293171823948729348710298301928331,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "string",
|
||||
"schema": {"type": "string"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a bignum is not a string",
|
||||
"data": 98249283749234923498293171823948729348710298301928331,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "integer comparison",
|
||||
"schema": {"maximum": 18446744073709551615},
|
||||
"tests": [
|
||||
{
|
||||
"description": "comparison works for high numbers",
|
||||
"data": 18446744073709551600,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "float comparison with high precision",
|
||||
"schema": {
|
||||
"maximum": 972783798187987123879878123.18878137,
|
||||
"exclusiveMaximum": true
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "comparison works for high numbers",
|
||||
"data": 972783798187987123879878123.188781371,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "integer comparison",
|
||||
"schema": {"minimum": -18446744073709551615},
|
||||
"tests": [
|
||||
{
|
||||
"description": "comparison works for very negative numbers",
|
||||
"data": -18446744073709551600,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "float comparison with high precision on negative numbers",
|
||||
"schema": {
|
||||
"minimum": -972783798187987123879878123.18878137,
|
||||
"exclusiveMinimum": true
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "comparison works for very negative numbers",
|
||||
"data": -972783798187987123879878123.188781371,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
49
node_modules/is-my-json-valid/test/json-schema-draft4/default.json
generated
vendored
Normal file
49
node_modules/is-my-json-valid/test/json-schema-draft4/default.json
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
[
|
||||
{
|
||||
"description": "invalid type for default",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "integer",
|
||||
"default": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid when property is specified",
|
||||
"data": {"foo": 13},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "still valid when the invalid default is used",
|
||||
"data": {},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "invalid string value for default",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"bar": {
|
||||
"type": "string",
|
||||
"minLength": 4,
|
||||
"default": "bad"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid when property is specified",
|
||||
"data": {"bar": "good"},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "still valid when the invalid default is used",
|
||||
"data": {},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
32
node_modules/is-my-json-valid/test/json-schema-draft4/definitions.json
generated
vendored
Normal file
32
node_modules/is-my-json-valid/test/json-schema-draft4/definitions.json
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
[
|
||||
{
|
||||
"description": "valid definition",
|
||||
"schema": {"$ref": "http://json-schema.org/draft-04/schema#"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid definition schema",
|
||||
"data": {
|
||||
"definitions": {
|
||||
"foo": {"type": "integer"}
|
||||
}
|
||||
},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "invalid definition",
|
||||
"schema": {"$ref": "http://json-schema.org/draft-04/schema#"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "invalid definition schema",
|
||||
"data": {
|
||||
"definitions": {
|
||||
"foo": {"type": 1}
|
||||
}
|
||||
},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
113
node_modules/is-my-json-valid/test/json-schema-draft4/dependencies.json
generated
vendored
Normal file
113
node_modules/is-my-json-valid/test/json-schema-draft4/dependencies.json
generated
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
[
|
||||
{
|
||||
"description": "dependencies",
|
||||
"schema": {
|
||||
"dependencies": {"bar": ["foo"]}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "neither",
|
||||
"data": {},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "nondependant",
|
||||
"data": {"foo": 1},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "with dependency",
|
||||
"data": {"foo": 1, "bar": 2},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "missing dependency",
|
||||
"data": {"bar": 2},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-objects",
|
||||
"data": "foo",
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "multiple dependencies",
|
||||
"schema": {
|
||||
"dependencies": {"quux": ["foo", "bar"]}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "neither",
|
||||
"data": {},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "nondependants",
|
||||
"data": {"foo": 1, "bar": 2},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "with dependencies",
|
||||
"data": {"foo": 1, "bar": 2, "quux": 3},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "missing dependency",
|
||||
"data": {"foo": 1, "quux": 2},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "missing other dependency",
|
||||
"data": {"bar": 1, "quux": 2},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "missing both dependencies",
|
||||
"data": {"quux": 1},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "multiple dependencies subschema",
|
||||
"schema": {
|
||||
"dependencies": {
|
||||
"bar": {
|
||||
"properties": {
|
||||
"foo": {"type": "integer"},
|
||||
"bar": {"type": "integer"}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid",
|
||||
"data": {"foo": 1, "bar": 2},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "no dependency",
|
||||
"data": {"foo": "quux"},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "wrong type",
|
||||
"data": {"foo": "quux", "bar": 2},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "wrong type other",
|
||||
"data": {"foo": 2, "bar": "quux"},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "wrong type both",
|
||||
"data": {"foo": "quux", "bar": "quux"},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
72
node_modules/is-my-json-valid/test/json-schema-draft4/enum.json
generated
vendored
Normal file
72
node_modules/is-my-json-valid/test/json-schema-draft4/enum.json
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
[
|
||||
{
|
||||
"description": "simple enum validation",
|
||||
"schema": {"enum": [1, 2, 3]},
|
||||
"tests": [
|
||||
{
|
||||
"description": "one of the enum is valid",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "something else is invalid",
|
||||
"data": 4,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "heterogeneous enum validation",
|
||||
"schema": {"enum": [6, "foo", [], true, {"foo": 12}]},
|
||||
"tests": [
|
||||
{
|
||||
"description": "one of the enum is valid",
|
||||
"data": [],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "something else is invalid",
|
||||
"data": null,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "objects are deep compared",
|
||||
"data": {"foo": false},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "enums in properties",
|
||||
"schema": {
|
||||
"type":"object",
|
||||
"properties": {
|
||||
"foo": {"enum":["foo"]},
|
||||
"bar": {"enum":["bar"]}
|
||||
},
|
||||
"required": ["bar"]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "both properties are valid",
|
||||
"data": {"foo":"foo", "bar":"bar"},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "missing optional property is valid",
|
||||
"data": {"bar":"bar"},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "missing required property is invalid",
|
||||
"data": {"foo":"foo"},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "missing all properties is invalid",
|
||||
"data": {},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
143
node_modules/is-my-json-valid/test/json-schema-draft4/format.json
generated
vendored
Normal file
143
node_modules/is-my-json-valid/test/json-schema-draft4/format.json
generated
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
[
|
||||
{
|
||||
"description": "validation of date-time strings",
|
||||
"schema": {"format": "date-time"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a valid date-time string",
|
||||
"data": "1963-06-19T08:30:06.283185Z",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an invalid date-time string",
|
||||
"data": "06/19/1963 08:30:06 PST",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "only RFC3339 not all of ISO 8601 are valid",
|
||||
"data": "2013-350T01:01:01",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "validation of URIs",
|
||||
"schema": {"format": "uri"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a valid URI",
|
||||
"data": "http://foo.bar/?baz=qux#quux",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an invalid URI",
|
||||
"data": "\\\\WINDOWS\\fileshare",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an invalid URI though valid URI reference",
|
||||
"data": "abc",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "validation of e-mail addresses",
|
||||
"schema": {"format": "email"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a valid e-mail address",
|
||||
"data": "joe.bloggs@example.com",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an invalid e-mail address",
|
||||
"data": "2962",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "validation of IP addresses",
|
||||
"schema": {"format": "ipv4"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a valid IP address",
|
||||
"data": "192.168.0.1",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an IP address with too many components",
|
||||
"data": "127.0.0.0.1",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an IP address with out-of-range values",
|
||||
"data": "256.256.256.256",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an IP address without 4 components",
|
||||
"data": "127.0",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an IP address as an integer",
|
||||
"data": "0x7f000001",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "validation of IPv6 addresses",
|
||||
"schema": {"format": "ipv6"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a valid IPv6 address",
|
||||
"data": "::1",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an IPv6 address with out-of-range values",
|
||||
"data": "12345::",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an IPv6 address with too many components",
|
||||
"data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an IPv6 address containing illegal characters",
|
||||
"data": "::laptop",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "validation of host names",
|
||||
"schema": {"format": "hostname"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a valid host name",
|
||||
"data": "www.example.com",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a host name starting with an illegal character",
|
||||
"data": "-a-host-name-that-starts-with--",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a host name containing illegal characters",
|
||||
"data": "not_a_valid_host_name",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a host name with a component too long",
|
||||
"data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
46
node_modules/is-my-json-valid/test/json-schema-draft4/items.json
generated
vendored
Normal file
46
node_modules/is-my-json-valid/test/json-schema-draft4/items.json
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
[
|
||||
{
|
||||
"description": "a schema given for items",
|
||||
"schema": {
|
||||
"items": {"type": "integer"}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid items",
|
||||
"data": [ 1, 2, 3 ],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "wrong type of items",
|
||||
"data": [1, "x"],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-arrays",
|
||||
"data": {"foo" : "bar"},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "an array of schemas for items",
|
||||
"schema": {
|
||||
"items": [
|
||||
{"type": "integer"},
|
||||
{"type": "string"}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "correct types",
|
||||
"data": [ 1, "foo" ],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "wrong types",
|
||||
"data": [ "foo", 1 ],
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
28
node_modules/is-my-json-valid/test/json-schema-draft4/maxItems.json
generated
vendored
Normal file
28
node_modules/is-my-json-valid/test/json-schema-draft4/maxItems.json
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
[
|
||||
{
|
||||
"description": "maxItems validation",
|
||||
"schema": {"maxItems": 2},
|
||||
"tests": [
|
||||
{
|
||||
"description": "shorter is valid",
|
||||
"data": [1],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "exact length is valid",
|
||||
"data": [1, 2],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "too long is invalid",
|
||||
"data": [1, 2, 3],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-arrays",
|
||||
"data": "foobar",
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
28
node_modules/is-my-json-valid/test/json-schema-draft4/maxLength.json
generated
vendored
Normal file
28
node_modules/is-my-json-valid/test/json-schema-draft4/maxLength.json
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
[
|
||||
{
|
||||
"description": "maxLength validation",
|
||||
"schema": {"maxLength": 2},
|
||||
"tests": [
|
||||
{
|
||||
"description": "shorter is valid",
|
||||
"data": "f",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "exact length is valid",
|
||||
"data": "fo",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "too long is invalid",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-strings",
|
||||
"data": 100,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
28
node_modules/is-my-json-valid/test/json-schema-draft4/maxProperties.json
generated
vendored
Normal file
28
node_modules/is-my-json-valid/test/json-schema-draft4/maxProperties.json
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
[
|
||||
{
|
||||
"description": "maxProperties validation",
|
||||
"schema": {"maxProperties": 2},
|
||||
"tests": [
|
||||
{
|
||||
"description": "shorter is valid",
|
||||
"data": {"foo": 1},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "exact length is valid",
|
||||
"data": {"foo": 1, "bar": 2},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "too long is invalid",
|
||||
"data": {"foo": 1, "bar": 2, "baz": 3},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-objects",
|
||||
"data": "foobar",
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
42
node_modules/is-my-json-valid/test/json-schema-draft4/maximum.json
generated
vendored
Normal file
42
node_modules/is-my-json-valid/test/json-schema-draft4/maximum.json
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
[
|
||||
{
|
||||
"description": "maximum validation",
|
||||
"schema": {"maximum": 3.0},
|
||||
"tests": [
|
||||
{
|
||||
"description": "below the maximum is valid",
|
||||
"data": 2.6,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "above the maximum is invalid",
|
||||
"data": 3.5,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-numbers",
|
||||
"data": "x",
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "exclusiveMaximum validation",
|
||||
"schema": {
|
||||
"maximum": 3.0,
|
||||
"exclusiveMaximum": true
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "below the maximum is still valid",
|
||||
"data": 2.2,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "boundary point is invalid",
|
||||
"data": 3.0,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
28
node_modules/is-my-json-valid/test/json-schema-draft4/minItems.json
generated
vendored
Normal file
28
node_modules/is-my-json-valid/test/json-schema-draft4/minItems.json
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
[
|
||||
{
|
||||
"description": "minItems validation",
|
||||
"schema": {"minItems": 1},
|
||||
"tests": [
|
||||
{
|
||||
"description": "longer is valid",
|
||||
"data": [1, 2],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "exact length is valid",
|
||||
"data": [1],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "too short is invalid",
|
||||
"data": [],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-arrays",
|
||||
"data": "",
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
28
node_modules/is-my-json-valid/test/json-schema-draft4/minLength.json
generated
vendored
Normal file
28
node_modules/is-my-json-valid/test/json-schema-draft4/minLength.json
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
[
|
||||
{
|
||||
"description": "minLength validation",
|
||||
"schema": {"minLength": 2},
|
||||
"tests": [
|
||||
{
|
||||
"description": "longer is valid",
|
||||
"data": "foo",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "exact length is valid",
|
||||
"data": "fo",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "too short is invalid",
|
||||
"data": "f",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-strings",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
28
node_modules/is-my-json-valid/test/json-schema-draft4/minProperties.json
generated
vendored
Normal file
28
node_modules/is-my-json-valid/test/json-schema-draft4/minProperties.json
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
[
|
||||
{
|
||||
"description": "minProperties validation",
|
||||
"schema": {"minProperties": 1},
|
||||
"tests": [
|
||||
{
|
||||
"description": "longer is valid",
|
||||
"data": {"foo": 1, "bar": 2},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "exact length is valid",
|
||||
"data": {"foo": 1},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "too short is invalid",
|
||||
"data": {},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-objects",
|
||||
"data": "",
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
42
node_modules/is-my-json-valid/test/json-schema-draft4/minimum.json
generated
vendored
Normal file
42
node_modules/is-my-json-valid/test/json-schema-draft4/minimum.json
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
[
|
||||
{
|
||||
"description": "minimum validation",
|
||||
"schema": {"minimum": 1.1},
|
||||
"tests": [
|
||||
{
|
||||
"description": "above the minimum is valid",
|
||||
"data": 2.6,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "below the minimum is invalid",
|
||||
"data": 0.6,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-numbers",
|
||||
"data": "x",
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "exclusiveMinimum validation",
|
||||
"schema": {
|
||||
"minimum": 1.1,
|
||||
"exclusiveMinimum": true
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "above the minimum is still valid",
|
||||
"data": 1.2,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "boundary point is invalid",
|
||||
"data": 1.1,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
96
node_modules/is-my-json-valid/test/json-schema-draft4/multipleOf.json
generated
vendored
Normal file
96
node_modules/is-my-json-valid/test/json-schema-draft4/multipleOf.json
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
[
|
||||
{
|
||||
"description": "by int",
|
||||
"schema": {"multipleOf": 2},
|
||||
"tests": [
|
||||
{
|
||||
"description": "int by int",
|
||||
"data": 10,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "int by int fail",
|
||||
"data": 7,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-numbers",
|
||||
"data": "foo",
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "by number",
|
||||
"schema": {"multipleOf": 1.5},
|
||||
"tests": [
|
||||
{
|
||||
"description": "zero is multiple of anything",
|
||||
"data": 0,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "4.5 is multiple of 1.5",
|
||||
"data": 4.5,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "35 is not multiple of 1.5",
|
||||
"data": 35,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "by small number",
|
||||
"schema": {"multipleOf": 0.0001},
|
||||
"tests": [
|
||||
{
|
||||
"description": "0.0075 is multiple of 0.0001",
|
||||
"data": 0.0075,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "0.00751 is not multiple of 0.0001",
|
||||
"data": 0.00751,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "by decimal number where floating point precision is wrong",
|
||||
"schema": {"multipleOf": 0.01},
|
||||
"tests": [
|
||||
{
|
||||
"description": "Number 2 is multiple of 0.01",
|
||||
"data": 2,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "Number 2.1 is multiple of 0.01",
|
||||
"data": 2.1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "Number 2.2 is multiple of 0.01",
|
||||
"data": 2.2,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "Number 2.3 is multiple of 0.01",
|
||||
"data": 2.3,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "Number 2.4 is multiple of 0.01",
|
||||
"data": 2.4,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "Number 1.211 is not multiple of 0.01",
|
||||
"data": 1.211,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
96
node_modules/is-my-json-valid/test/json-schema-draft4/not.json
generated
vendored
Normal file
96
node_modules/is-my-json-valid/test/json-schema-draft4/not.json
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
[
|
||||
{
|
||||
"description": "not",
|
||||
"schema": {
|
||||
"not": {"type": "integer"}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "allowed",
|
||||
"data": "foo",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "disallowed",
|
||||
"data": 1,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "not multiple types",
|
||||
"schema": {
|
||||
"not": {"type": ["integer", "boolean"]}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid",
|
||||
"data": "foo",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "mismatch",
|
||||
"data": 1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "other mismatch",
|
||||
"data": true,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "not more complex schema",
|
||||
"schema": {
|
||||
"not": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "match",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "other match",
|
||||
"data": {"foo": 1},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "mismatch",
|
||||
"data": {"foo": "bar"},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "forbidden property",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"foo": {
|
||||
"not": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "property present",
|
||||
"data": {"foo": 1, "bar": 2},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "property absent",
|
||||
"data": {"bar": 1, "baz": 2},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
]
|
18
node_modules/is-my-json-valid/test/json-schema-draft4/nullAndFormat.json
generated
vendored
Normal file
18
node_modules/is-my-json-valid/test/json-schema-draft4/nullAndFormat.json
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"description": "validation of null and format",
|
||||
"schema": {"type": ["null", "string"], "format": "date-time"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a valid date-time string",
|
||||
"data": "1963-06-19T08:30:06.283185Z",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "allow null",
|
||||
"data": null,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
18
node_modules/is-my-json-valid/test/json-schema-draft4/nullAndObject.json
generated
vendored
Normal file
18
node_modules/is-my-json-valid/test/json-schema-draft4/nullAndObject.json
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"description": "multiple types of null and object containing properties",
|
||||
"schema": {
|
||||
"type": ["null", "object"],
|
||||
"properties": {
|
||||
"foo": {}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "null is valid",
|
||||
"data": null,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
68
node_modules/is-my-json-valid/test/json-schema-draft4/oneOf.json
generated
vendored
Normal file
68
node_modules/is-my-json-valid/test/json-schema-draft4/oneOf.json
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
[
|
||||
{
|
||||
"description": "oneOf",
|
||||
"schema": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"minimum": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "first oneOf valid",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "second oneOf valid",
|
||||
"data": 2.5,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "both oneOf valid",
|
||||
"data": 3,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "neither oneOf valid",
|
||||
"data": 1.5,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "oneOf with base schema",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"oneOf" : [
|
||||
{
|
||||
"minLength": 2
|
||||
},
|
||||
{
|
||||
"maxLength": 4
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "mismatch base schema",
|
||||
"data": 3,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "one oneOf valid",
|
||||
"data": "foobar",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "both oneOf valid",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
23
node_modules/is-my-json-valid/test/json-schema-draft4/pattern.json
generated
vendored
Normal file
23
node_modules/is-my-json-valid/test/json-schema-draft4/pattern.json
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
[
|
||||
{
|
||||
"description": "pattern validation",
|
||||
"schema": {"pattern": "^a*$"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a matching pattern is valid",
|
||||
"data": "aaa",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a non-matching pattern is invalid",
|
||||
"data": "abc",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-strings",
|
||||
"data": true,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
110
node_modules/is-my-json-valid/test/json-schema-draft4/patternProperties.json
generated
vendored
Normal file
110
node_modules/is-my-json-valid/test/json-schema-draft4/patternProperties.json
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
[
|
||||
{
|
||||
"description":
|
||||
"patternProperties validates properties matching a regex",
|
||||
"schema": {
|
||||
"patternProperties": {
|
||||
"f.*o": {"type": "integer"}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a single valid match is valid",
|
||||
"data": {"foo": 1},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "multiple valid matches is valid",
|
||||
"data": {"foo": 1, "foooooo" : 2},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a single invalid match is invalid",
|
||||
"data": {"foo": "bar", "fooooo": 2},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "multiple invalid matches is invalid",
|
||||
"data": {"foo": "bar", "foooooo" : "baz"},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "ignores non-objects",
|
||||
"data": 12,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "multiple simultaneous patternProperties are validated",
|
||||
"schema": {
|
||||
"patternProperties": {
|
||||
"a*": {"type": "integer"},
|
||||
"aaa*": {"maximum": 20}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "a single valid match is valid",
|
||||
"data": {"a": 21},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a simultaneous match is valid",
|
||||
"data": {"aaaa": 18},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "multiple matches is valid",
|
||||
"data": {"a": 21, "aaaa": 18},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an invalid due to one is invalid",
|
||||
"data": {"a": "bar"},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an invalid due to the other is invalid",
|
||||
"data": {"aaaa": 31},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an invalid due to both is invalid",
|
||||
"data": {"aaa": "foo", "aaaa": 31},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "regexes are not anchored by default and are case sensitive",
|
||||
"schema": {
|
||||
"patternProperties": {
|
||||
"[0-9]{2,}": { "type": "boolean" },
|
||||
"X_": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "non recognized members are ignored",
|
||||
"data": { "answer 1": "42" },
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "recognized members are accounted for",
|
||||
"data": { "a31b": null },
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "regexes are case sensitive",
|
||||
"data": { "a_x_3": 3 },
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "regexes are case sensitive, 2",
|
||||
"data": { "a_X_3": 3 },
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
92
node_modules/is-my-json-valid/test/json-schema-draft4/properties.json
generated
vendored
Normal file
92
node_modules/is-my-json-valid/test/json-schema-draft4/properties.json
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
[
|
||||
{
|
||||
"description": "object properties validation",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"foo": {"type": "integer"},
|
||||
"bar": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "both properties present and valid is valid",
|
||||
"data": {"foo": 1, "bar": "baz"},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "one property invalid is invalid",
|
||||
"data": {"foo": 1, "bar": {}},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "both properties invalid is invalid",
|
||||
"data": {"foo": [], "bar": {}},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "doesn't invalidate other properties",
|
||||
"data": {"quux": []},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "ignores non-objects",
|
||||
"data": [],
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description":
|
||||
"properties, patternProperties, additionalProperties interaction",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"foo": {"type": "array", "maxItems": 3},
|
||||
"bar": {"type": "array"}
|
||||
},
|
||||
"patternProperties": {"f.o": {"minItems": 2}},
|
||||
"additionalProperties": {"type": "integer"}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "property validates property",
|
||||
"data": {"foo": [1, 2]},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "property invalidates property",
|
||||
"data": {"foo": [1, 2, 3, 4]},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "patternProperty invalidates property",
|
||||
"data": {"foo": []},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "patternProperty validates nonproperty",
|
||||
"data": {"fxo": [1, 2]},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "patternProperty invalidates nonproperty",
|
||||
"data": {"fxo": []},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "additionalProperty ignores property",
|
||||
"data": {"bar": []},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "additionalProperty validates others",
|
||||
"data": {"quux": 3},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "additionalProperty invalidates others",
|
||||
"data": {"quux": "foo"},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
128
node_modules/is-my-json-valid/test/json-schema-draft4/ref.json
generated
vendored
Normal file
128
node_modules/is-my-json-valid/test/json-schema-draft4/ref.json
generated
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
[
|
||||
{
|
||||
"description": "root pointer ref",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"foo": {"$ref": "#"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "match",
|
||||
"data": {"foo": false},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "recursive match",
|
||||
"data": {"foo": {"foo": false}},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "mismatch",
|
||||
"data": {"bar": false},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "recursive mismatch",
|
||||
"data": {"foo": {"bar": false}},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "relative pointer ref to object",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"foo": {"type": "integer"},
|
||||
"bar": {"$ref": "#/properties/foo"}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "match",
|
||||
"data": {"bar": 3},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "mismatch",
|
||||
"data": {"bar": true},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "relative pointer ref to array",
|
||||
"schema": {
|
||||
"items": [
|
||||
{"type": "integer"},
|
||||
{"$ref": "#/items/0"}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "match array",
|
||||
"data": [1, 2],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "mismatch array",
|
||||
"data": [1, "foo"],
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "escaped pointer ref",
|
||||
"schema": {
|
||||
"tilda~field": {"type": "integer"},
|
||||
"slash/field": {"type": "integer"},
|
||||
"percent%field": {"type": "integer"},
|
||||
"properties": {
|
||||
"tilda": {"$ref": "#/tilda~0field"},
|
||||
"slash": {"$ref": "#/slash~1field"},
|
||||
"percent": {"$ref": "#/percent%25field"}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "slash",
|
||||
"data": {"slash": "aoeu"},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "tilda",
|
||||
"data": {"tilda": "aoeu"},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "percent",
|
||||
"data": {"percent": "aoeu"},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "nested refs",
|
||||
"schema": {
|
||||
"definitions": {
|
||||
"a": {"type": "integer"},
|
||||
"b": {"$ref": "#/definitions/a"},
|
||||
"c": {"$ref": "#/definitions/b"}
|
||||
},
|
||||
"$ref": "#/definitions/c"
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "nested ref valid",
|
||||
"data": 5,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "nested ref invalid",
|
||||
"data": "a",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
74
node_modules/is-my-json-valid/test/json-schema-draft4/refRemote.json
generated
vendored
Normal file
74
node_modules/is-my-json-valid/test/json-schema-draft4/refRemote.json
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
[
|
||||
{
|
||||
"description": "remote ref",
|
||||
"schema": {"$ref": "http://localhost:1234/integer.json"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "remote ref valid",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "remote ref invalid",
|
||||
"data": "a",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "fragment within remote ref",
|
||||
"schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "remote fragment valid",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "remote fragment invalid",
|
||||
"data": "a",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "ref within remote ref",
|
||||
"schema": {
|
||||
"$ref": "http://localhost:1234/subSchemas.json#/refToInteger"
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "ref within ref valid",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "ref within ref invalid",
|
||||
"data": "a",
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "change resolution scope",
|
||||
"schema": {
|
||||
"id": "http://localhost:1234/",
|
||||
"items": {
|
||||
"id": "folder/",
|
||||
"items": {"$ref": "folderInteger.json"}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "changed scope ref valid",
|
||||
"data": [[1]],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "changed scope ref invalid",
|
||||
"data": [["a"]],
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
39
node_modules/is-my-json-valid/test/json-schema-draft4/required.json
generated
vendored
Normal file
39
node_modules/is-my-json-valid/test/json-schema-draft4/required.json
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
[
|
||||
{
|
||||
"description": "required validation",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"foo": {},
|
||||
"bar": {}
|
||||
},
|
||||
"required": ["foo"]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "present required property is valid",
|
||||
"data": {"foo": 1},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "non-present required property is invalid",
|
||||
"data": {"bar": 1},
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "required default validation",
|
||||
"schema": {
|
||||
"properties": {
|
||||
"foo": {}
|
||||
}
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "not required by default",
|
||||
"data": {},
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
330
node_modules/is-my-json-valid/test/json-schema-draft4/type.json
generated
vendored
Normal file
330
node_modules/is-my-json-valid/test/json-schema-draft4/type.json
generated
vendored
Normal file
@ -0,0 +1,330 @@
|
||||
[
|
||||
{
|
||||
"description": "integer type matches integers",
|
||||
"schema": {"type": "integer"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "an integer is an integer",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a float is not an integer",
|
||||
"data": 1.1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a string is not an integer",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an object is not an integer",
|
||||
"data": {},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an array is not an integer",
|
||||
"data": [],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a boolean is not an integer",
|
||||
"data": true,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "null is not an integer",
|
||||
"data": null,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "number type matches numbers",
|
||||
"schema": {"type": "number"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "an integer is a number",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a float is a number",
|
||||
"data": 1.1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a string is not a number",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an object is not a number",
|
||||
"data": {},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an array is not a number",
|
||||
"data": [],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a boolean is not a number",
|
||||
"data": true,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "null is not a number",
|
||||
"data": null,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "string type matches strings",
|
||||
"schema": {"type": "string"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "1 is not a string",
|
||||
"data": 1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a float is not a string",
|
||||
"data": 1.1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a string is a string",
|
||||
"data": "foo",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an object is not a string",
|
||||
"data": {},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an array is not a string",
|
||||
"data": [],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a boolean is not a string",
|
||||
"data": true,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "null is not a string",
|
||||
"data": null,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "object type matches objects",
|
||||
"schema": {"type": "object"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "an integer is not an object",
|
||||
"data": 1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a float is not an object",
|
||||
"data": 1.1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a string is not an object",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an object is an object",
|
||||
"data": {},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "an array is not an object",
|
||||
"data": [],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a boolean is not an object",
|
||||
"data": true,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "null is not an object",
|
||||
"data": null,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "array type matches arrays",
|
||||
"schema": {"type": "array"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "an integer is not an array",
|
||||
"data": 1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a float is not an array",
|
||||
"data": 1.1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a string is not an array",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an object is not an array",
|
||||
"data": {},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an array is not an array",
|
||||
"data": [],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a boolean is not an array",
|
||||
"data": true,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "null is not an array",
|
||||
"data": null,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "boolean type matches booleans",
|
||||
"schema": {"type": "boolean"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "an integer is not a boolean",
|
||||
"data": 1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a float is not a boolean",
|
||||
"data": 1.1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a string is not a boolean",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an object is not a boolean",
|
||||
"data": {},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an array is not a boolean",
|
||||
"data": [],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a boolean is not a boolean",
|
||||
"data": true,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "null is not a boolean",
|
||||
"data": null,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "null type matches only the null object",
|
||||
"schema": {"type": "null"},
|
||||
"tests": [
|
||||
{
|
||||
"description": "an integer is not null",
|
||||
"data": 1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a float is not null",
|
||||
"data": 1.1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a string is not null",
|
||||
"data": "foo",
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an object is not null",
|
||||
"data": {},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an array is not null",
|
||||
"data": [],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a boolean is not null",
|
||||
"data": true,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "null is null",
|
||||
"data": null,
|
||||
"valid": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "multiple types can be specified in an array",
|
||||
"schema": {"type": ["integer", "string"]},
|
||||
"tests": [
|
||||
{
|
||||
"description": "an integer is valid",
|
||||
"data": 1,
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a string is valid",
|
||||
"data": "foo",
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "a float is invalid",
|
||||
"data": 1.1,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an object is invalid",
|
||||
"data": {},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "an array is invalid",
|
||||
"data": [],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "a boolean is invalid",
|
||||
"data": true,
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "null is invalid",
|
||||
"data": null,
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
79
node_modules/is-my-json-valid/test/json-schema-draft4/uniqueItems.json
generated
vendored
Normal file
79
node_modules/is-my-json-valid/test/json-schema-draft4/uniqueItems.json
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
[
|
||||
{
|
||||
"description": "uniqueItems validation",
|
||||
"schema": {"uniqueItems": true},
|
||||
"tests": [
|
||||
{
|
||||
"description": "unique array of integers is valid",
|
||||
"data": [1, 2],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "non-unique array of integers is invalid",
|
||||
"data": [1, 1],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "numbers are unique if mathematically unequal",
|
||||
"data": [1.0, 1.00, 1],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "unique array of objects is valid",
|
||||
"data": [{"foo": "bar"}, {"foo": "baz"}],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "non-unique array of objects is invalid",
|
||||
"data": [{"foo": "bar"}, {"foo": "bar"}],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "unique array of nested objects is valid",
|
||||
"data": [
|
||||
{"foo": {"bar" : {"baz" : true}}},
|
||||
{"foo": {"bar" : {"baz" : false}}}
|
||||
],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "non-unique array of nested objects is invalid",
|
||||
"data": [
|
||||
{"foo": {"bar" : {"baz" : true}}},
|
||||
{"foo": {"bar" : {"baz" : true}}}
|
||||
],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "unique array of arrays is valid",
|
||||
"data": [["foo"], ["bar"]],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "non-unique array of arrays is invalid",
|
||||
"data": [["foo"], ["foo"]],
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"description": "1 and true are unique",
|
||||
"data": [1, true],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "0 and false are unique",
|
||||
"data": [0, false],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "unique heterogeneous types are valid",
|
||||
"data": [{}, [1], true, null, 1],
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"description": "non-unique heterogeneous types are invalid",
|
||||
"data": [{}, [1], true, null, {}, 1],
|
||||
"valid": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
23
node_modules/is-my-json-valid/test/json-schema.js
generated
vendored
Normal file
23
node_modules/is-my-json-valid/test/json-schema.js
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
var tape = require('tape')
|
||||
var fs = require('fs')
|
||||
var validator = require('../')
|
||||
|
||||
var files = fs.readdirSync(__dirname+'/json-schema-draft4')
|
||||
.map(function(file) {
|
||||
if (file === 'definitions.json') return null
|
||||
if (file === 'refRemote.json') return null
|
||||
return require('./json-schema-draft4/'+file)
|
||||
})
|
||||
.filter(Boolean)
|
||||
|
||||
files.forEach(function(file) {
|
||||
file.forEach(function(f) {
|
||||
tape('json-schema-test-suite '+f.description, function(t) {
|
||||
var validate = validator(f.schema)
|
||||
f.tests.forEach(function(test) {
|
||||
t.same(validate(test.data), test.valid, test.description)
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
471
node_modules/is-my-json-valid/test/misc.js
generated
vendored
Normal file
471
node_modules/is-my-json-valid/test/misc.js
generated
vendored
Normal file
@ -0,0 +1,471 @@
|
||||
var tape = require('tape')
|
||||
var cosmic = require('./fixtures/cosmic')
|
||||
var validator = require('../')
|
||||
var validatorRequire = require('../require')
|
||||
|
||||
tape('simple', function(t) {
|
||||
var schema = {
|
||||
required: true,
|
||||
type: 'object',
|
||||
properties: {
|
||||
hello: {type:'string', required:true}
|
||||
}
|
||||
}
|
||||
|
||||
var validate = validator(schema)
|
||||
|
||||
t.ok(validate({hello: 'world'}), 'should be valid')
|
||||
t.notOk(validate(), 'should be invalid')
|
||||
t.notOk(validate({}), 'should be invalid')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('data is undefined', function (t) {
|
||||
var validate = validator({type: 'string'})
|
||||
|
||||
t.notOk(validate(null))
|
||||
t.notOk(validate(undefined))
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('advanced', function(t) {
|
||||
var validate = validator(cosmic.schema)
|
||||
|
||||
t.ok(validate(cosmic.valid), 'should be valid')
|
||||
t.notOk(validate(cosmic.invalid), 'should be invalid')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('greedy/false', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
x: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
required: ['x', 'y']
|
||||
});
|
||||
t.notOk(validate({}), 'should be invalid')
|
||||
t.strictEqual(validate.errors.length, 2);
|
||||
t.strictEqual(validate.errors[0].field, 'data.x')
|
||||
t.strictEqual(validate.errors[0].message, 'is required')
|
||||
t.strictEqual(validate.errors[1].field, 'data.y')
|
||||
t.strictEqual(validate.errors[1].message, 'is required')
|
||||
t.notOk(validate({x: 'string'}), 'should be invalid')
|
||||
t.strictEqual(validate.errors.length, 1);
|
||||
t.strictEqual(validate.errors[0].field, 'data.y')
|
||||
t.strictEqual(validate.errors[0].message, 'is required')
|
||||
t.notOk(validate({x: 'string', y: 'value'}), 'should be invalid')
|
||||
t.strictEqual(validate.errors.length, 1);
|
||||
t.strictEqual(validate.errors[0].field, 'data.x')
|
||||
t.strictEqual(validate.errors[0].message, 'is the wrong type')
|
||||
t.end();
|
||||
});
|
||||
|
||||
tape('greedy/true', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
x: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
required: ['x', 'y']
|
||||
}, {
|
||||
greedy: true
|
||||
});
|
||||
t.notOk(validate({}), 'should be invalid')
|
||||
t.strictEqual(validate.errors.length, 2);
|
||||
t.strictEqual(validate.errors[0].field, 'data.x')
|
||||
t.strictEqual(validate.errors[0].message, 'is required')
|
||||
t.strictEqual(validate.errors[1].field, 'data.y')
|
||||
t.strictEqual(validate.errors[1].message, 'is required')
|
||||
t.notOk(validate({x: 'string'}), 'should be invalid')
|
||||
t.strictEqual(validate.errors.length, 2);
|
||||
t.strictEqual(validate.errors[0].field, 'data.y')
|
||||
t.strictEqual(validate.errors[0].message, 'is required')
|
||||
t.strictEqual(validate.errors[1].field, 'data.x')
|
||||
t.strictEqual(validate.errors[1].message, 'is the wrong type')
|
||||
t.notOk(validate({x: 'string', y: 'value'}), 'should be invalid')
|
||||
t.strictEqual(validate.errors.length, 1);
|
||||
t.strictEqual(validate.errors[0].field, 'data.x')
|
||||
t.strictEqual(validate.errors[0].message, 'is the wrong type')
|
||||
t.ok(validate({x: 1, y: 'value'}), 'should be invalid')
|
||||
t.end();
|
||||
});
|
||||
|
||||
tape('additional props', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
additionalProperties: false
|
||||
}, {
|
||||
verbose: true
|
||||
})
|
||||
|
||||
t.ok(validate({}))
|
||||
t.notOk(validate({foo:'bar'}))
|
||||
t.ok(validate.errors[0].value === 'data.foo', 'should output the property not allowed in verbose mode')
|
||||
t.strictEqual(validate.errors[0].type, 'object', 'error object should contain the type')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('array', function(t) {
|
||||
var validate = validator({
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
})
|
||||
|
||||
t.notOk(validate({}), 'wrong type')
|
||||
t.notOk(validate(), 'is required')
|
||||
t.ok(validate(['test']))
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('nested array', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
list: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.notOk(validate({}), 'is required')
|
||||
t.ok(validate({list:['test']}))
|
||||
t.notOk(validate({list:[1]}))
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('enum', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
enum: [42]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.notOk(validate({}), 'is required')
|
||||
t.ok(validate({foo:42}))
|
||||
t.notOk(validate({foo:43}))
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('minimum/maximum', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'number',
|
||||
minimum: 0,
|
||||
maximum: 0
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.notOk(validate({foo:-42}))
|
||||
t.ok(validate({foo:0}))
|
||||
t.notOk(validate({foo:42}))
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('exclusiveMinimum/exclusiveMaximum', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'number',
|
||||
minimum: 10,
|
||||
maximum: 20,
|
||||
exclusiveMinimum: true,
|
||||
exclusiveMaximum: true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.notOk(validate({foo:10}))
|
||||
t.ok(validate({foo:11}))
|
||||
t.notOk(validate({foo:20}))
|
||||
t.ok(validate({foo:19}))
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('minimum/maximum number type', function(t) {
|
||||
var validate = validator({
|
||||
type: ['integer', 'null'],
|
||||
minimum: 1,
|
||||
maximum: 100
|
||||
})
|
||||
|
||||
t.notOk(validate(-1))
|
||||
t.notOk(validate(0))
|
||||
t.ok(validate(null))
|
||||
t.ok(validate(1))
|
||||
t.ok(validate(100))
|
||||
t.notOk(validate(101))
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom format', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'string',
|
||||
format: 'as'
|
||||
}
|
||||
}
|
||||
}, {formats: {as:/^a+$/}})
|
||||
|
||||
t.notOk(validate({foo:''}), 'not as')
|
||||
t.notOk(validate({foo:'b'}), 'not as')
|
||||
t.notOk(validate({foo:'aaab'}), 'not as')
|
||||
t.ok(validate({foo:'a'}), 'as')
|
||||
t.ok(validate({foo:'aaaaaa'}), 'as')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('custom format function', function(t) {
|
||||
var validate = validator({
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'string',
|
||||
format: 'as'
|
||||
}
|
||||
}
|
||||
}, {formats: {as:function(s) { return /^a+$/.test(s) } }})
|
||||
|
||||
t.notOk(validate({foo:''}), 'not as')
|
||||
t.notOk(validate({foo:'b'}), 'not as')
|
||||
t.notOk(validate({foo:'aaab'}), 'not as')
|
||||
t.ok(validate({foo:'a'}), 'as')
|
||||
t.ok(validate({foo:'aaaaaa'}), 'as')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('do not mutate schema', function(t) {
|
||||
var sch = {
|
||||
items: [
|
||||
{}
|
||||
],
|
||||
additionalItems: {
|
||||
type: 'integer'
|
||||
}
|
||||
}
|
||||
|
||||
var copy = JSON.parse(JSON.stringify(sch))
|
||||
|
||||
validator(sch)
|
||||
|
||||
t.same(sch, copy, 'did not mutate')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('#toJSON()', function(t) {
|
||||
var schema = {
|
||||
required: true,
|
||||
type: 'object',
|
||||
properties: {
|
||||
hello: {type:'string', required:true}
|
||||
}
|
||||
}
|
||||
|
||||
var validate = validator(schema)
|
||||
|
||||
t.deepEqual(validate.toJSON(), schema, 'should return original schema')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('external schemas', function(t) {
|
||||
var ext = {type: 'string'}
|
||||
var schema = {
|
||||
required: true,
|
||||
$ref: '#ext'
|
||||
}
|
||||
|
||||
var validate = validator(schema, {schemas: {ext:ext}})
|
||||
|
||||
t.ok(validate('hello string'), 'is a string')
|
||||
t.notOk(validate(42), 'not a string')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('external schema URIs', function(t) {
|
||||
var ext = {type: 'string'}
|
||||
var schema = {
|
||||
required: true,
|
||||
$ref: 'http://example.com/schemas/schemaURIs'
|
||||
}
|
||||
|
||||
var opts = {schemas:{}};
|
||||
opts.schemas['http://example.com/schemas/schemaURIs'] = ext;
|
||||
var validate = validator(schema, opts)
|
||||
|
||||
t.ok(validate('hello string'), 'is a string')
|
||||
t.notOk(validate(42), 'not a string')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('top-level external schema', function(t) {
|
||||
var defs = {
|
||||
"string": {
|
||||
type: "string"
|
||||
},
|
||||
"sex": {
|
||||
type: "string",
|
||||
enum: ["male", "female", "other"]
|
||||
}
|
||||
}
|
||||
var schema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
"name": { $ref: "definitions.json#/string" },
|
||||
"sex": { $ref: "definitions.json#/sex" }
|
||||
},
|
||||
required: ["name", "sex"]
|
||||
}
|
||||
|
||||
var validate = validator(schema, {
|
||||
schemas: {
|
||||
"definitions.json": defs
|
||||
}
|
||||
})
|
||||
t.ok(validate({name:"alice", sex:"female"}), 'is an object')
|
||||
t.notOk(validate({name:"alice", sex: "bob"}), 'recognizes external schema')
|
||||
t.notOk(validate({name:2, sex: "female"}), 'recognizes external schema')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('nested required array decl', function(t) {
|
||||
var schema = {
|
||||
properties: {
|
||||
x: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
y: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
z: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
required: ['z']
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ['x']
|
||||
}
|
||||
|
||||
var validate = validator(schema)
|
||||
|
||||
t.ok(validate({x: {}}), 'should be valid')
|
||||
t.notOk(validate({}), 'should not be valid')
|
||||
t.strictEqual(validate.errors[0].field, 'data.x', 'should output the missing field')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('verbose mode', function(t) {
|
||||
var schema = {
|
||||
required: true,
|
||||
type: 'object',
|
||||
properties: {
|
||||
hello: {
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var validate = validator(schema, {verbose: true})
|
||||
|
||||
t.ok(validate({hello: 'string'}), 'should be valid')
|
||||
t.notOk(validate({hello: 100}), 'should not be valid')
|
||||
t.strictEqual(validate.errors[0].value, 100, 'error object should contain the invalid value')
|
||||
t.strictEqual(validate.errors[0].type, 'string', 'error object should contain the type')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('additional props in verbose mode', function(t) {
|
||||
var schema = {
|
||||
type: 'object',
|
||||
required: true,
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'string'
|
||||
},
|
||||
'hello world': {
|
||||
type: 'object',
|
||||
required: true,
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var validate = validator(schema, {verbose: true})
|
||||
|
||||
validate({'hello world': {bar: 'string'}});
|
||||
|
||||
t.strictEqual(validate.errors[0].value, 'data["hello world"].bar', 'should output the path to the additional prop in the error')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('Date.now() is an integer', function(t) {
|
||||
var schema = {type: 'integer'}
|
||||
var validate = validator(schema)
|
||||
|
||||
t.ok(validate(Date.now()), 'is integer')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('field shows item index in arrays', function(t) {
|
||||
var schema = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'array',
|
||||
items: {
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var validate = validator(schema)
|
||||
|
||||
validate([
|
||||
[
|
||||
{ foo: 'test' },
|
||||
{ foo: 'test' }
|
||||
],
|
||||
[
|
||||
{ foo: 'test' },
|
||||
{ baz: 'test' }
|
||||
]
|
||||
])
|
||||
|
||||
t.strictEqual(validate.errors[0].field, 'data.1.1.foo', 'should output the field with specific index of failing item in the error')
|
||||
t.end()
|
||||
})
|
Reference in New Issue
Block a user