jsonschema
Advanced tools
Comparing version 1.2.5 to 1.2.6
@@ -67,3 +67,3 @@ 'use strict'; | ||
if (! res.valid && callback instanceof Function) { | ||
if (!res.valid && callback instanceof Function) { | ||
callback(res); | ||
@@ -70,0 +70,0 @@ } |
@@ -186,4 +186,4 @@ 'use strict'; | ||
} | ||
if (a instanceof Array) { | ||
if (!(b instanceof Array)) { | ||
if (Array.isArray(a)) { | ||
if (!Array.isArray(b)) { | ||
return false; | ||
@@ -190,0 +190,0 @@ } |
@@ -71,3 +71,3 @@ /* | ||
minProperties?: number | ||
required?: string[] | ||
required?: string[] | boolean | ||
additionalProperties?: boolean | Schema | ||
@@ -74,0 +74,0 @@ definitions?: { |
@@ -42,4 +42,4 @@ | ||
} | ||
scanArray(ourBase+'/items', ((schema.items instanceof Array)?schema.items:[schema.items])); | ||
scanArray(ourBase+'/extends', ((schema.extends instanceof Array)?schema.extends:[schema.extends])); | ||
scanArray(ourBase+'/items', (Array.isArray(schema.items)?schema.items:[schema.items])); | ||
scanArray(ourBase+'/extends', (Array.isArray(schema.extends)?schema.extends:[schema.extends])); | ||
scanSchema(ourBase+'/additionalItems', schema.additionalItems); | ||
@@ -58,3 +58,3 @@ scanObject(ourBase+'/properties', schema.properties); | ||
function scanArray(baseuri, schemas){ | ||
if(!(schemas instanceof Array)) return; | ||
if(!Array.isArray(schemas)) return; | ||
for(var i=0; i<schemas.length; i++){ | ||
@@ -61,0 +61,0 @@ scanSchema(baseuri+'/'+i, schemas[i]); |
@@ -66,3 +66,3 @@ 'use strict'; | ||
Validator.prototype.addSubSchemaArray = function addSubSchemaArray(baseuri, schemas) { | ||
if(!(schemas instanceof Array)) return; | ||
if(!Array.isArray(schemas)) return; | ||
for(var i=0; i<schemas.length; i++){ | ||
@@ -171,3 +171,3 @@ this.addSubSchema(baseuri, schemas[i]); | ||
if (schema['extends']) { | ||
if (schema['extends'] instanceof Array) { | ||
if (Array.isArray(schema['extends'])) { | ||
var schemaobj = {schema: schema, ctx: ctx}; | ||
@@ -319,5 +319,5 @@ schema['extends'].forEach(this.schemaTraverser.bind(this, schemaobj)); | ||
// TODO: fix this - see #15 | ||
return instance && (typeof instance) === 'object' && !(instance instanceof Array) && !(instance instanceof Date); | ||
return instance && (typeof instance === 'object') && !(Array.isArray(instance)) && !(instance instanceof Date); | ||
}; | ||
module.exports = Validator; |
{ | ||
"author": "Tom de Grunt <tom@degrunt.nl>", | ||
"name": "jsonschema", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "dependencies": {}, |
@@ -80,3 +80,15 @@ [![Build Status](https://secure.travis-ci.org/tdegrunt/jsonschema.svg)](http://travis-ci.org/tdegrunt/jsonschema) | ||
``` | ||
### Example for Array schema | ||
```json | ||
var arraySchema = { | ||
"type": "array", | ||
"items": { | ||
"properties": { | ||
"name": { "type": "string" }, | ||
"lastname": { "type": "string" } | ||
}, | ||
"required": ["name", "lastname"] | ||
} | ||
} | ||
``` | ||
For a comprehensive, annotated example illustrating all possible validation options, see [examples/all.js](./examples/all.js) | ||
@@ -190,3 +202,3 @@ | ||
if (schema.type && this.attributes.type.call(this, instance, schema, options, ctx.makeChild(schema, property))) { | ||
var types = (schema.type instanceof Array) ? schema.type : [schema.type]; | ||
var types = Array.isArray(schema.type) ? schema.type : [schema.type]; | ||
var coerced = undefined; | ||
@@ -193,0 +205,0 @@ |
63717
262