lib/param-parser.js
function parseBodyParam (req, res, next) {
  let params = getParams(req);

  params.some((param) => {
    if (param.in === "body") {
      util.debug('    Parsing the "%s" body parameter', param.name);

      if (_.isPlainObject(req.body) && _.isEmpty(req.body)) {
        if (param.type === "string" || (param.schema && param.schema.type === "string")) {
          // Convert {} to ""
          req.body = "";
        }
        else {
          // Convert {} to undefined
          req.body = undefined;
        }
      }

      // Parse the body
      req.body = parseParameter(param, req.body, param.schema);

      // There can only be one "body" parameter, so skip the rest
      return true;
    }
  });

  // If there are no body/formData parameters, then reset `req.body` to undefined
  if (params.length > 0) {
    let hasBody = params.some((param) => {
      return param.in === "body" || param.in === "formData";
    });

    if (!hasBody) {
      req.body = undefined;
    }
  }

  next();
}
function parseBodyParam (req, res, next) {
  let params = getParams(req);

  params.some((param) => {
    if (param.in === "body") {
      util.debug('    Parsing the "%s" body parameter', param.name);

      if (_.isPlainObject(req.body) && _.isEmpty(req.body)) {
        if (param.type === "string" || (param.schema && param.schema.type === "string")) {
          // Convert {} to ""
          req.body = "";
        }
        else {
          // Convert {} to undefined
          req.body = undefined;
        }
      }

      // Parse the body
      req.body = parseParameter(param, req.body, param.schema);

      // There can only be one "body" parameter, so skip the rest
      return true;
    }
  });

  // If there are no body/formData parameters, then reset `req.body` to undefined
  if (params.length > 0) {
    let hasBody = params.some((param) => {
      return param.in === "body" || param.in === "formData";
    });

    if (!hasBody) {
      req.body = undefined;
    }
  }

  next();
}
function parseBodyParam ( req , res , next ) { let params = getParams ( req ) ; params . some ( ( param ) => { if ( param . in === "body" ) { util . debug ( '    Parsing the "%s" body parameter' , param . name ) ; if ( _ . isPlainObject ( req . body ) && _ . isEmpty ( req . body ) ) { if ( param . type === "string" || ( param . schema && param . schema . type === "string" ) ) { // Convert {} to "" req . body = "" ; } else { // Convert {} to undefined req . body = undefined ; } } // Parse the body req . body = parseParameter ( param , req . body , param . schema ) ; // There can only be one "body" parameter, so skip the rest return true ; } } ) ; // If there are no body/formData parameters, then reset `req.body` to undefined if ( params . length > 0 ) { let hasBody = params . some ( ( param ) => { return param . in === "body" || param . in === "formData" ; } ) ; if ( ! hasBody ) { req . body = undefined ; } } next ( ) ; }
Parses the Swagger "body" parameter.
Parses the Swagger body parameter .