Lines Matching refs:instance

44 function isInstanceOfClass(instance, className) {
45 while ((instance = instance.__proto__)) {
46 if (instance.constructor.name == className)
64 * Validates an instance against a schema and accumulates errors. Usage:
105 notInstance: "Object must be an instance of *."
232 * Validates an instance against a schema. The instance can be any JavaScript
236 JSONSchemaValidator.prototype.validate = function(instance, schema, opt_path) {
248 // If the schema has an extends property, the instance must validate against
251 this.validate(instance, schema.extends, path);
253 // If the schema has a $ref property, the instance must validate against
260 this.validate(instance, this.getOrAddType(ref), path)
263 // If the schema has a choices property, the instance must validate against at
266 this.validateChoices(instance, schema, path);
270 // If the schema has an enum property, the instance must be one of those
273 if (!this.validateEnum(instance, schema, path))
278 if (!this.validateType(instance, schema, path))
284 this.validateObject(instance, schema, path);
287 this.validateArray(instance, schema, path);
290 this.validateString(instance, schema, path);
294 this.validateNumber(instance, schema, path);
301 * Validates an instance against a choices schema. The instance must match at
305 function(instance, schema, path) {
310 this.validate(instance, schema.choices[i], path);
322 * Validates an instance against a schema with an enum type. Populates the
323 * |errors| property, and returns a boolean indicating whether the instance
326 JSONSchemaValidator.prototype.validateEnum = function(instance, schema, path) {
328 if (instance === enumToString(schema.enum[i]))
338 * Validates an instance against an object schema and populates the errors
342 function(instance, schema, path) {
357 } else if (prop in instance && !isOptionalValue(instance[prop])) {
358 this.validate(instance[prop], schema.properties[prop], propPath);
368 if (!isInstanceOfClass(instance, schema.isInstanceOf))
379 // By default, additional properties are not allowed on instance objects. This
382 for (var prop in instance) {
387 if (!$Object.hasOwnProperty(instance, prop))
392 this.validate(instance[prop], schema.additionalProperties, propPath);
399 * Validates an instance against an array schema and populates the errors
402 JSONSchemaValidator.prototype.validateArray = function(instance, schema, path) {
406 if (schema.minItems && instance.length < schema.minItems) {
411 instance.length > schema.maxItems) {
417 for (var i = 0; i < instance.length; i++) {
418 this.validate(instance[i], schema.items, path + "." + i);
425 if (i in instance && !isOptionalValue(instance[i])) {
426 this.validate(instance[i], schema.items[i], itemPath);
433 for (var i = schema.items.length; i < instance.length; i++) {
435 this.validate(instance[i], schema.additionalProperties, itemPath);
438 if (instance.length > schema.items.length) {
449 function(instance, schema, path) {
450 if (schema.minLength && instance.length < schema.minLength)
453 if (schema.maxLength && instance.length > schema.maxLength)
456 if (schema.pattern && !schema.pattern.test(instance))
461 * Validates a number and populates the errors property. The instance is
465 function(instance, schema, path) {
469 if (isNaN(instance) ||
470 instance == Number.POSITIVE_INFINITY ||
471 instance == Number.NEGATIVE_INFINITY )
472 this.addError(path, "numberFiniteNotNan", [instance]);
474 if (schema.minimum !== undefined && instance < schema.minimum)
477 if (schema.maximum !== undefined && instance > schema.maximum)
481 if (schema.type === "integer" && (instance | 0) !== instance)
484 if (schema.maxDecimal && instance * Math.pow(10, schema.maxDecimal) % 1)
489 * Validates the primitive type of an instance and populates the errors
490 * property. Returns true if the instance validates, false otherwise.
492 JSONSchemaValidator.prototype.validateType = function(instance, schema, path) {
493 var actualType = JSONSchemaValidator.getType(instance);