api/failures/FailureReason.js
/**
		 * Validates that a candidate conforms to a schema, returning a rejected
		 * promise (with a serialized FailureReason) if a problem exists.
		 *
		 * @public
		 * @static
		 * @param {Schema|Enum} schema
		 * @param {Object} candidate
		 * @param {String=} description
		 * @returns {Promise}
		 */
Validates that a candidate conforms to a schema, returning a rejected
promise (with a serialized FailureReason) if a problem exists.


Validates that a candidate conforms to a schema returning a rejected promise ( with a serialized FailureReason ) if a problem exists .
static validateSchema(schema, candidate, description) {
			return Promise.resolve()
				.then(() => {
					let schemaToUse;
					if (schema instanceof Schema) {
						schemaToUse = schema;
					} else if (schema.schema && schema.schema instanceof Schema) {
						schemaToUse = schema.schema;
					} else {
						schemaToUse = null;
					}
					const fields = schemaToUse.getInvalidFields(candidate);
					let failure;
					if (fields.length !== 0) {
						failure = FailureReason.forRequest({endpoint: { description: (description || `serialize data into ${schema.name}`) }})
							.addItem(FailureType.REQUEST_INPUT_MALFORMED, { }, true);
						failure = fields.reduce((accumulator, field) => {
							accumulator.addItem(FailureType.REQUEST_PARAMETER_MALFORMED, { name: field.name });
							return accumulator;
						}, failure);
					} else {
						failure = null;
					}
					if (failure !== null) {
						return Promise.reject(failure.format());
					} else {
						return Promise.resolve(null);
					}
				});
		}
static validateSchema ( schema , candidate , description ) { return Promise . resolve ( ) . then ( ( ) => { let schemaToUse ; if ( schema instanceof Schema ) { schemaToUse = schema ; } else if ( schema . schema && schema . schema instanceof Schema ) { schemaToUse = schema . schema ; } else { schemaToUse = null ; } const fields = schemaToUse . getInvalidFields ( candidate ) ; let failure ; if ( fields . length !== 0 ) { failure = FailureReason . forRequest ( { endpoint : { description : ( description || ` ${ schema . name } ` ) } } ) . addItem ( FailureType . REQUEST_INPUT_MALFORMED , { } , true ) ; failure = fields . reduce ( ( accumulator , field ) => { accumulator . addItem ( FailureType . REQUEST_PARAMETER_MALFORMED , { name : field . name } ) ; return accumulator ; } , failure ) ; } else { failure = null ; } if ( failure !== null ) { return Promise . reject ( failure . format ( ) ) ; } else { return Promise . resolve ( null ) ; } } ) ; }
Validates that a candidate conforms to a schema, returning a rejected
 promise (with a serialized FailureReason) if a problem exists.
Validates that a candidate conforms to a schema returning a rejected promise ( with a serialized FailureReason ) if a problem exists .