validating the core schema [validate(schema)] causes validate to choke on the '$schema' instance property; [validate(schema,schema)], which should be equivalent, adds an extra 'null' entry to the result. Deleting the $schema property before validating results in a single 'null' in result.errors.
var schema = require('document/document').tmp['http://json-schema.org/draft-03/schema'];
var v = require('document/validate');
var sys = require('sys');
var result;
sys.debug('----- SCHEMA ----- \n'+sys.inspect(schema));
sys.debug('\n\n');
sys.debug('----- VALIDATE: -----');
result = v.validate(schema);
sys.debug('result = v.validate(schema);'); // should validate
sys.debug('----- RESULT 1 ----- \n'+sys.inspect(result));
result = v.validate(schema, schema); // should be equiv. to 1.
sys.debug('result = v.validate(schema, schema);');
sys.debug('----- RESULT 2 ----- \n'+sys.inspect(result));
delete schema['$schema'];
result = v.validate(schema); // no schema to validate against
sys.debug('result = v.validate(schema);');
sys.debug('----- RESULT 3 ----- \n'+sys.inspect(result));
result = v.validate(schema, schema); // should validate
sys.debug('result = v.validate(schema, schema);');
sys.debug('----- RESULT 4 ----- \n'+sys.inspect(result));
DEBUG: ----- SCHEMA -----
{ '$schema': 'http://json-schema.org/draft-03/schema#'
, id: 'http://json-schema.org/draft-03/schema#'
, type: 'object'
, properties:
{ type:
{ type: [Object]
, items: [Object]
, uniqueItems: true
, default: 'any'
}
, properties:
{ type: 'object'
, additionalProperties: [Object]
, default: {}
}
, patternProperties:
{ type: 'object'
, additionalProperties: [Object]
, default: {}
}
, additionalProperties: { type: [Object], default: {} }
, items: { type: [Object], items: [Object], default: {} }
, additionalItems: { type: [Object], default: {} }
, required: { type: 'boolean', default: false }
, dependencies:
{ type: 'object'
, additionalProperties: [Object]
, default: {}
}
, minimum: { type: 'number' }
, maximum: { type: 'number' }
, exclusiveMinimum: { type: 'boolean', default: false }
, exclusiveMaximum: { type: 'boolean', default: false }
, minItems: { type: 'integer', minimum: 0, default: 0 }
, maxItems: { type: 'integer', minimum: 0 }
, uniqueItems: { type: 'boolean', default: false }
, pattern: { type: 'string', format: 'regex' }
, minLength: { type: 'integer', minimum: 0, default: 0 }
, maxLength: { type: 'integer' }
, enum: { type: 'array', minItems: 1, uniqueItems: true }
, default: { type: 'any' }
, title: { type: 'string' }
, description: { type: 'string' }
, format: { type: 'string' }
, divisibleBy:
{ type: 'number'
, minimum: 0
, exclusiveMinimum: true
, default: 1
}
, disallow: { type: [Object], items: [Object], uniqueItems: true }
, extends: { type: [Object], items: [Object], default: {} }
, id: { type: 'string', format: 'uri' }
, '$ref': { type: 'string', format: 'uri' }
, '$schema': { type: 'string', format: 'uri' }
}
, dependencies:
{ exclusiveMinimum: 'minimum'
, exclusiveMaximum: 'maximum'
}
, default: {}
}
DEBUG:
DEBUG: ----- VALIDATE: -----
DEBUG: result = v.validate(schema);
DEBUG: ----- RESULT 1 -----
{ valid: false
, errors:
[ { property: ''
, message: 'Invalid schema/property definition http://json-schema.org/draft-03/schema#'
}
]
}
DEBUG: result = v.validate(schema, schema);
DEBUG: ----- RESULT 2 -----
{ valid: false
, errors:
[ null
, { property: ''
, message: 'Invalid schema/property definition http://json-schema.org/draft-03/schema#'
}
]
}
DEBUG: result = v.validate(schema);
DEBUG: ----- RESULT 3 -----
{ valid: true, errors: [] }
DEBUG: result = v.validate(schema, schema);
DEBUG: ----- RESULT 4 -----
{ valid: false, errors: [ null ] }