lib/framework/middleware.js
function body(ctx) {
  if (['HEAD', 'GET'].indexOf(ctx.operation.spec.method) >= 0) return;

  var consumeMimes = ctx.operation.spec.consumes ||
    ctx.operation.resource.api.spec.consumes || [];
  var mimes = lodash.intersection(consumeMimes,
    Object.keys(ctx.router.decoder));
  var prefix = describe(ctx);

  if (!mimes.length) {
    debug(prefix + 'body middleware disabled (no consumes)');
    return;
  }

  var env = ctx.operation.resource.api.env;
  var options = validateOptions(ctx.operation, 'form', false);
  var schema = transform.parameters(ctx.operation.spec, 'body');

  if (!schema) {
    debug(prefix + 'body middleware disabled (no schema)');
    return;
  }

  return function(req, res, next) {
    var mime = is(req, mimes);
    var bodyErr;

    if (mime) {
      var body;

      if (req.sf.text) {
        try {
          body = ctx.router.decoder[mime](req.sf.text);
        } catch (err) {
          debug(prefix + 'body decoder failed', err);

          bodyErr = new Error('Decode body failed');
          bodyErr.statusCode = 400;
          bodyErr.parent = err;
          bodyErr.expose = true;

          return next(bodyErr);
        }
      } else if (schema.required) {
        bodyErr = new Error('Body required');
        bodyErr.statusCode = 400;
        bodyErr.expose = true;

        return next(bodyErr);
      } else {
        return next();
      }

      req.sf.body = body;

      if (validate(res, env.validate(schema, { body: body }, options))) {
        next();
      }
    } else if (schema.required) {
      bodyErr = new Error('Body required');
      bodyErr.statusCode = 400;
      bodyErr.expose = true;

      return next(bodyErr);
    } else {
      next();
    }
  };
}
function body(ctx) {
  if (['HEAD', 'GET'].indexOf(ctx.operation.spec.method) >= 0) return;

  var consumeMimes = ctx.operation.spec.consumes ||
    ctx.operation.resource.api.spec.consumes || [];
  var mimes = lodash.intersection(consumeMimes,
    Object.keys(ctx.router.decoder));
  var prefix = describe(ctx);

  if (!mimes.length) {
    debug(prefix + 'body middleware disabled (no consumes)');
    return;
  }

  var env = ctx.operation.resource.api.env;
  var options = validateOptions(ctx.operation, 'form', false);
  var schema = transform.parameters(ctx.operation.spec, 'body');

  if (!schema) {
    debug(prefix + 'body middleware disabled (no schema)');
    return;
  }

  return function(req, res, next) {
    var mime = is(req, mimes);
    var bodyErr;

    if (mime) {
      var body;

      if (req.sf.text) {
        try {
          body = ctx.router.decoder[mime](req.sf.text);
        } catch (err) {
          debug(prefix + 'body decoder failed', err);

          bodyErr = new Error('Decode body failed');
          bodyErr.statusCode = 400;
          bodyErr.parent = err;
          bodyErr.expose = true;

          return next(bodyErr);
        }
      } else if (schema.required) {
        bodyErr = new Error('Body required');
        bodyErr.statusCode = 400;
        bodyErr.expose = true;

        return next(bodyErr);
      } else {
        return next();
      }

      req.sf.body = body;

      if (validate(res, env.validate(schema, { body: body }, options))) {
        next();
      }
    } else if (schema.required) {
      bodyErr = new Error('Body required');
      bodyErr.statusCode = 400;
      bodyErr.expose = true;

      return next(bodyErr);
    } else {
      next();
    }
  };
}
function body ( ctx ) { if ( [ 'HEAD' , 'GET' ] . indexOf ( ctx . operation . spec . method ) >= 0 ) return ; var consumeMimes = ctx . operation . spec . consumes || ctx . operation . resource . api . spec . consumes || [ ] ; var mimes = lodash . intersection ( consumeMimes , Object . keys ( ctx . router . decoder ) ) ; var prefix = describe ( ctx ) ; if ( ! mimes . length ) { debug ( prefix + 'body middleware disabled (no consumes)' ) ; return ; } var env = ctx . operation . resource . api . env ; var options = validateOptions ( ctx . operation , 'form' , false ) ; var schema = transform . parameters ( ctx . operation . spec , 'body' ) ; if ( ! schema ) { debug ( prefix + 'body middleware disabled (no schema)' ) ; return ; } return function ( req , res , next ) { var mime = is ( req , mimes ) ; var bodyErr ; if ( mime ) { var body ; if ( req . sf . text ) { try { body = ctx . router . decoder [ mime ] ( req . sf . text ) ; } catch ( err ) { debug ( prefix + 'body decoder failed' , err ) ; bodyErr = new Error ( 'Decode body failed' ) ; bodyErr . statusCode = 400 ; bodyErr . parent = err ; bodyErr . expose = true ; return next ( bodyErr ) ; } } else if ( schema . required ) { bodyErr = new Error ( 'Body required' ) ; bodyErr . statusCode = 400 ; bodyErr . expose = true ; return next ( bodyErr ) ; } else { return next ( ) ; } req . sf . body = body ; if ( validate ( res , env . validate ( schema , { body : body } , options ) ) ) { next ( ) ; } } else if ( schema . required ) { bodyErr = new Error ( 'Body required' ) ; bodyErr . statusCode = 400 ; bodyErr . expose = true ; return next ( bodyErr ) ; } else { next ( ) ; } } ; }
Validate body based on Swagger spec.
Validate body based on Swagger spec .