validation

Accessor to the data validation API


addType

Adds a new data type, to be used for document validation.

Arguments

Copied to clipboard!
addType(Type);

Arguments Type Description
Type
object
A class implementing the abstract BaseValidationType class

validate

Validates the content of a request body (mutates the request).

Arguments

Copied to clipboard!
validate(request, [verbose]);

Arguments Type Description
request Request Request object with a non-empty body content
verbose
boolean
If true, returns an exhaustive validation report, instead of failing at the first error encountered

Return

The validate function returns a promise, and if relevant, default values are applied to the provided request.

If a validation error occurs, the behavior depends on the validation optional parameter:

  • false (default): the promise is rejected with the first error encountered
  • true: the promise is resolved even if the validation fails. The promise resolves a validation status report, containing the following properties:
    • validation: {boolean} validation state
    • errorMessages: {array} the exhaustive list of encountered errors