lib/param-parser.js
function parseParameter (param, value, schema) {
  if (value === undefined) {
    if (param.required) {
      // The parameter is required, but was not provided, so throw a 400 error
      let errCode = 400;

      if (param.in === "header" && param.name.toLowerCase() === "content-length") {
        // Special case for the Content-Length header.  It has it's own HTTP error code.
        errCode = 411; // (Length Required)
      }

      // noinspection ExceptionCaughtLocallyJS
      throw ono({ status: errCode }, 'Missing required %s parameter "%s"', param.in, param.name);
    }
    else if (schema.default === undefined) {
      // The parameter is optional, and there's no default value
      return undefined;
    }
  }

  // Special case for the Content-Length header.  It has it's own HTTP error code (411 Length Required)
  if (value === "" && param.in === "header" && param.name.toLowerCase() === "content-length") {
    throw ono({ status: 411 }, 'Missing required header parameter "%s"', param.name);
  }

  try {
    return new JsonSchema(schema).parse(value);
  }
  catch (e) {
    throw ono(e, { status: e.status }, 'The "%s" %s parameter is invalid (%j)',
      param.name, param.in, value === undefined ? param.default : value);
  }
}
function parseParameter (param, value, schema) {
  if (value === undefined) {
    if (param.required) {
      // The parameter is required, but was not provided, so throw a 400 error
      let errCode = 400;

      if (param.in === "header" && param.name.toLowerCase() === "content-length") {
        // Special case for the Content-Length header.  It has it's own HTTP error code.
        errCode = 411; // (Length Required)
      }

      // noinspection ExceptionCaughtLocallyJS
      throw ono({ status: errCode }, 'Missing required %s parameter "%s"', param.in, param.name);
    }
    else if (schema.default === undefined) {
      // The parameter is optional, and there's no default value
      return undefined;
    }
  }

  // Special case for the Content-Length header.  It has it's own HTTP error code (411 Length Required)
  if (value === "" && param.in === "header" && param.name.toLowerCase() === "content-length") {
    throw ono({ status: 411 }, 'Missing required header parameter "%s"', param.name);
  }

  try {
    return new JsonSchema(schema).parse(value);
  }
  catch (e) {
    throw ono(e, { status: e.status }, 'The "%s" %s parameter is invalid (%j)',
      param.name, param.in, value === undefined ? param.default : value);
  }
}
function parseParameter ( param , value , schema ) { if ( value === undefined ) { if ( param . required ) { // The parameter is required, but was not provided, so throw a 400 error let errCode = 400 ; if ( param . in === "header" && param . name . toLowerCase ( ) === "content-length" ) { // Special case for the Content-Length header.  It has it's own HTTP error code. errCode = 411 ; // (Length Required) } // noinspection ExceptionCaughtLocallyJS throw ono ( { status : errCode } , 'Missing required %s parameter "%s"' , param . in , param . name ) ; } else if ( schema . default === undefined ) { // The parameter is optional, and there's no default value return undefined ; } } // Special case for the Content-Length header.  It has it's own HTTP error code (411 Length Required) if ( value === "" && param . in === "header" && param . name . toLowerCase ( ) === "content-length" ) { throw ono ( { status : 411 } , 'Missing required header parameter "%s"' , param . name ) ; } try { return new JsonSchema ( schema ) . parse ( value ) ; } catch ( e ) { throw ono ( e , { status : e . status } , 'The "%s" %s parameter is invalid (%j)' , param . name , param . in , value === undefined ? param . default : value ) ; } }
Parses the given parameter, using the given JSON schema definition.

@param   {object}    param  - The Parameter API object
@param   {*}         value  - The value to be parsed (it will be coerced if needed)
@param   {object}    schema - The JSON schema definition for the parameter
@returns {*}                - The parsed value
Parses the given parameter using the given JSON schema definition .