lib/middleware/validator.js
function check(log, validity, req, res, type, full, finalValidator, callback) {
  var validator, v;

  log.info.call(log, 'deserializing and validating request body', {
    serializerType: type,
    full: full,
    finalValidator: finalValidator ? true : false
  });

  if (!req.body) {
    callback(new Error('Empty Request Body'));
    return;
  }

  if (!validity.hasOwnProperty(type)) {
    throw new Error('Unrecognized type: ' + type);
  }

  v = new Valve(validity[type]);

  if (req.ctx) {
    req.ctx.setValve(v);
  }

  if (finalValidator) {
    v.addFinalValidator(finalValidator);
  }

  v.baton = {req: req};
  validator = full ? v.check : v.checkPartial;

  validator.call(v, req.body, function(err, cleaned) {
    if (err) {
      log.debug.call(log, 'validation_check (error)', {request: req, body: req.body});
      callback(err);
      return;
    }

    log.debug.call(log, 'validation_check (success)', {request: req, cleaned: cleaned});
    callback(null, cleaned);
  });
}
function check(log, validity, req, res, type, full, finalValidator, callback) {
  var validator, v;

  log.info.call(log, 'deserializing and validating request body', {
    serializerType: type,
    full: full,
    finalValidator: finalValidator ? true : false
  });

  if (!req.body) {
    callback(new Error('Empty Request Body'));
    return;
  }

  if (!validity.hasOwnProperty(type)) {
    throw new Error('Unrecognized type: ' + type);
  }

  v = new Valve(validity[type]);

  if (req.ctx) {
    req.ctx.setValve(v);
  }

  if (finalValidator) {
    v.addFinalValidator(finalValidator);
  }

  v.baton = {req: req};
  validator = full ? v.check : v.checkPartial;

  validator.call(v, req.body, function(err, cleaned) {
    if (err) {
      log.debug.call(log, 'validation_check (error)', {request: req, body: req.body});
      callback(err);
      return;
    }

    log.debug.call(log, 'validation_check (success)', {request: req, cleaned: cleaned});
    callback(null, cleaned);
  });
}
function check ( log , validity , req , res , type , full , finalValidator , callback ) { var validator , v ; log . info . call ( log , 'deserializing and validating request body' , { serializerType : type , full : full , finalValidator : finalValidator ? true : false } ) ; if ( ! req . body ) { callback ( new Error ( 'Empty Request Body' ) ) ; return ; } if ( ! validity . hasOwnProperty ( type ) ) { throw new Error ( 'Unrecognized type: ' + type ) ; } v = new Valve ( validity [ type ] ) ; if ( req . ctx ) { req . ctx . setValve ( v ) ; } if ( finalValidator ) { v . addFinalValidator ( finalValidator ) ; } v . baton = { req : req } ; validator = full ? v . check : v . checkPartial ; validator . call ( v , req . body , function ( err , cleaned ) { if ( err ) { log . debug . call ( log , 'validation_check (error)' , { request : req , body : req . body } ) ; callback ( err ) ; return ; } log . debug . call ( log , 'validation_check (success)' , { request : req , cleaned : cleaned } ) ; callback ( null , cleaned ) ; } ) ; }
Verifies the object given. I thought about having it detect things
but that just seemed to be too leaky.

Serializes the object pointed to by data, into XML or JSON,
depending on the request headers.  Using the object_name we look
up a consistent mapping of the Object -> XML/JSON layout.

@param {Object} log Log method.
@param {Valve} validity Valve validity object.
@param {http.ServerRequest} req http request.
@param {http.ServerResponse} res http response.
@param {String} type The type of the object.
@param {boolean} full If true, perform full validation; otherwise, perform
partial validation.
@param {?Function} finalValidator Optional finalValidator which can perform
validator on the whole cleaned object.
@param {Function(err, cleaned)} callback A function to be called when the
verification is complete.  Sets err to a non-null error message string if
an error has occurred.  Sets cleaned to the cleaned version of the body, if
applicable.
Verifies the object given . I thought about having it detect things but that just seemed to be too leaky .