This repository was archived by the owner on Dec 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Validator
fogine edited this page Jul 19, 2016
·
3 revisions
var inspector = require('json-inspector');
var validator = new inspector.Validator(schema, options, validatorManager);| Argument | Type | Description | |
|---|---|---|---|
| schema | Object / Function | validator's schema definition. if it's function, the function is expected to return an object. | |
| options | Object | optional | See options table bellow |
| validatorManager | ValidatorManager | optional | instance of inspector.ValidatorManager |
| Key | Type | Default | Description |
|---|---|---|---|
| required | Boolean | false | Determines whether data are required by default or not |
| filterData | Boolean | true | If true, data which are not described in schema definition are wiped out |
| failOnUnexpectedData | Boolean | false | Applies only if filterData=false. if true, a validation process will fail when unexpected data are found |
| message | String | "Invalid data for %p ,got: %v" | Default error message for all failed assertions. If you want assertion specific error messages, see Multilanguage support |
| failOnFirstErr | Boolean | false | if true, it will stop validation process on first error encountered. Therefore validation is rejected only with single error message. |
| nullable | Boolean | false | if true, null value is treated as "empty" value - same as if value was not send at all - data property with empty value is ingored if it is not specificely set as required |
| validationError | Function | ValidationError | constructor function used for building error objects |
| validationMultiError | Function | ValidationMultiError | constructor function used for building multi-error object in case of multiple validation errors |
validator.validate(data, customSchema, options); //=> returns self (validator)| Argument | Type | Description | |
|---|---|---|---|
| data | mixed | data value being inspected | |
| customSchema | Object | optional | custom schema definition which will be merged with schema definition of a validator object |
| options | Object | optional | Same as Validator's options |