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

  var mimes = ctx.operation.spec.consumes ||
    ctx.operation.resource.api.spec.consumes || [];
  var mime = 'application/x-www-form-urlencoded';
  var prefix = describe(ctx);
  var decode = ctx.router.decoder[mime];

  if (mimes.indexOf(mime) === -1) {
    debug(prefix + 'form middleware disabled (no consumes)');
    return;
  }

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

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

  schema = {
    type: 'object',
    properties: { form: schema },
    required: ['form'],
  };

  return function(req, res, next) {
    if (is(req, [mime])) {
      var form;

      try {
        form = decode(req.sf.text);
      } catch (err) {
        return next(err);
      }

      form = req.sf.form = lodash.clone(form);

      if (validate(res, env.validate(schema, { form: form }, options))) {
        next();
      }
    } else {
      next();
    }
  };
}
function form(ctx) {
  if (['HEAD', 'GET'].indexOf(ctx.operation.spec.method) >= 0) return;

  var mimes = ctx.operation.spec.consumes ||
    ctx.operation.resource.api.spec.consumes || [];
  var mime = 'application/x-www-form-urlencoded';
  var prefix = describe(ctx);
  var decode = ctx.router.decoder[mime];

  if (mimes.indexOf(mime) === -1) {
    debug(prefix + 'form middleware disabled (no consumes)');
    return;
  }

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

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

  schema = {
    type: 'object',
    properties: { form: schema },
    required: ['form'],
  };

  return function(req, res, next) {
    if (is(req, [mime])) {
      var form;

      try {
        form = decode(req.sf.text);
      } catch (err) {
        return next(err);
      }

      form = req.sf.form = lodash.clone(form);

      if (validate(res, env.validate(schema, { form: form }, options))) {
        next();
      }
    } else {
      next();
    }
  };
}
function form ( ctx ) { if ( [ 'HEAD' , 'GET' ] . indexOf ( ctx . operation . spec . method ) >= 0 ) return ; var mimes = ctx . operation . spec . consumes || ctx . operation . resource . api . spec . consumes || [ ] ; var mime = 'application/x-www-form-urlencoded' ; var prefix = describe ( ctx ) ; var decode = ctx . router . decoder [ mime ] ; if ( mimes . indexOf ( mime ) === - 1 ) { debug ( prefix + 'form middleware disabled (no consumes)' ) ; return ; } var env = ctx . operation . resource . api . env ; var options = validateOptions ( ctx . operation , 'form' , true ) ; var schema = transform . parameters ( ctx . operation . spec , 'form' ) ; if ( ! schema ) { debug ( prefix + 'form middleware disabled (no schema)' ) ; return ; } schema = { type : 'object' , properties : { form : schema } , required : [ 'form' ] , } ; return function ( req , res , next ) { if ( is ( req , [ mime ] ) ) { var form ; try { form = decode ( req . sf . text ) ; } catch ( err ) { return next ( err ) ; } form = req . sf . form = lodash . clone ( form ) ; if ( validate ( res , env . validate ( schema , { form : form } , options ) ) ) { next ( ) ; } } else { next ( ) ; } } ; }
Validate form based on Swagger spec.
Validate form based on Swagger spec .