documents/schema

Descripción

The validator mixin provides access to the features of the JSON validation system

Detalles

Miembros


schema :object

Descripción

The schema that defines the validation rules. This should probably be defined at the prototype for each
object or model classification. It can be an anonymous schema defined right here, or this can be
registered schema names to use, or just a single name

Detalles
object

schemas :object

Descripción

If you want to register multiple schemas, use this property instead

Detalles
object

_defaultSchemaName :string|function

Descripción

The default name of the scheman when you use anonymous schemas. You can define this at the prototype for classified
schemas. The can also

Detalles
string | function

validationOptions :object|function

Descripción

The options to pass to the validator when it runs

Detalles
object | function

Métodos


validate( [ record ], schemaName [, options ] ) → {object}

Descripción

Validate an object against the schema

Parámetros
Nombre Tipo Atributos Descripción
record object <optional>

The record to validate

schemaName string | object

The name of a previously registered schema

options object <optional>

Options to pass to the validator

Returns
Ejemplos
// This supports these signatures:

instance.validate(record, schemaName, options);


instance.validate(); // this, this._defaultSchemaName, this.validationOptions
instance.validate(record); // record, this._defaultSchemaName, this.validationOptions
instance.validate(schemaName); //this, schemaName, this.validationOptions
instance.validate(record, schemaName); //record, schemaName, this.validationOptions
instance.validate(schemaName, options); //this, schemaName, this.validationOptions
Detalles

registerSchemas( schemas )

Descripción

Initialize the schema collection by registering the with the handler. You can call this at any time and as often as you like. It will be called once
by the constructor on any instance schemas

Parámetros
Nombre Tipo Descripción
schemas hash

A hash of schemas where the key is the name of the schema

Detalles

extract( [ record [, schema ] ] )

Descripción

Extracts only the elements of the object that are defined in the schema

Parámetros
Nombre Tipo Atributos Descripción
record object <optional>

The record to extract from

schema string <optional>

The name of the schema to attach

Detalles

addType( name, operation ) → {boolean}

Descripción

Create a type to be used in your schemas to define new validators

Parámetros
Nombre Tipo Descripción
name string

The name of the type

operation function

What to do with the type.

Nombre Tipo Descripción
value object

The value to validation

Returns
Detalles

addFormat( name, formatter ) → {boolean}

Descripción

It is also possible to add support for additional string formats through the addFormat function.

Parámetros
Nombre Tipo Descripción
name string

The name of the formatter

formatter function

How to format it

Nombre Tipo Descripción
value object

The value to format

Returns
Detalles

addCheck( name, formatter ) → {boolean}

Descripción

It is possible to add support for custom checks (i.e., minItems, maxItems, minLength, maxLength, etc.) through the addCheck function

Parámetros
Nombre Tipo Descripción
name string

The name of the check

formatter function

Perform the check

Nombre Tipo Descripción
value object

The value to check followed by any parameters from the schema

Returns
Detalles

addTypeCoercion( name, coercer ) → {boolean}

Descripción

Custom coercion rules

Parámetros
Nombre Tipo Descripción
name string

The name of the coercion

coercer function

Perform the coercion

Nombre Tipo Descripción
value object

The value to coerce

Returns
Detalles

getSchema( [ schemaName ] ) → {object}

Descripción

Get a registered schema by name

Parámetros
Nombre Tipo Atributos Descripción
schemaName string <optional>
Returns
Detalles

extract( [ schema [, src ] ] ) → {object}

Descripción

This method will create a new object that contains only the fields and no methods or other artifacts. This is useful
for creating objects to pass over the wire or save in a table. This is not deeply copied, so changes made to the
extracted object will be represented in this class for reference objects.

Parámetros
Nombre Tipo Atributos Descripción
schema string <optional>

The schema name to use

src object <optional>

The object to extract fields from

Returns

Data-only version of the class instance.

Detalles

defaultDoc( schema ) → {object}

Descripción

Builds a default document based on the schema. What this does is create a document from schema and for each property
that has a default value or is required, the resultant object will contain that property. It is useful for extending
values from some source that may be incomplete, like options or some such.

Parámetros
Nombre Tipo Descripción
schema json-schema

A schema to use to create the default document

Returns
Detalles