# Mixin: documents/schema

## documents/schema

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

Source:
  - documents/schema.js, line 17

### Members

#### _defaultSchemaName :string|function

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

  ##### Type:

  - string | function
  Source:
    - documents/schema.js, line 44

#### schema :object

  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

  ##### Type:

  - object
  Source:
    - documents/schema.js, line 19

#### schemas :object

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

  ##### Type:

  - object
  Source:
    - documents/schema.js, line 29

#### validationOptions :object|function

  The options to pass to the validator when it runs

  ##### Type:

  - object | function
  Source:
    - documents/schema.js, line 54

### Methods

#### addCheck(name, formatter) → {boolean}

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

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `name` | string | The name of the check

  `formatter`

  function

  Perform the check

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `value` | object | The value to check followed by any parameters from the schema

  Source:
    - documents/schema.js, line 165

  ##### Returns:

  Type
    boolean

#### addFormat(name, formatter) → {boolean}

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

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `name` | string | The name of the formatter

  `formatter`

  function

  How to format it

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `value` | object | The value to format

  Source:
    - documents/schema.js, line 153

  ##### Returns:

  Type
    boolean

#### addType(name, operation) → {boolean}

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

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `name` | string | The name of the type

  `operation`

  function

  What to do with the type.

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `value` | object | The value to validation

  Source:
    - documents/schema.js, line 141

  ##### Returns:

  Type
    boolean

#### addTypeCoercion(name, coercer) → {boolean}

  Custom coercion rules

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `name` | string | The name of the coercion

  `coercer`

  function

  Perform the coercion

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `value` | object | The value to coerce

  Source:
    - documents/schema.js, line 177

  ##### Returns:

  Type
    boolean

#### defaultDoc(schema) → {object}

  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.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `schema` | json-schema | A schema to use to create the default document

  Source:
    - documents/schema.js, line 239

  ##### Returns:

  Type
    object

#### extract(record, schema)

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

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `record` | object | <optional> | The record to extract from
  `schema` | string | <optional> | The name of the schema to attach

  Source:
    - documents/schema.js, line 122

#### getSchema(schemaName) → {object}

  Get a registered schema by name

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `schemaName` | string | <optional> |

  Source:
    - documents/schema.js, line 190

  ##### Returns:

  Type
    object

#### registerSchemas(schemas)

  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

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `schemas` | hash | A hash of schemas where the key is the name of the schema

  Source:
    - documents/schema.js, line 101

#### validate(record, schemaName, options) → {object}

  Validate an object against the schema

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `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

  Source:
    - documents/schema.js, line 62

  ##### Returns:

  Type
    object

  ##### Example

      // 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