lib/respectify.js
function getParams(obj) {
    var defs = []

    for (var name in obj) {
      var data = obj[name]
        , fromPath = ~required.indexOf(name)

      // If string, assume a single data type
      if (typeof data === 'string') {
        data = data.split(',')
      }

      // If array, assume array of data types
      if (Array.isArray(data)) {
        data = obj[name] = {
          dataTypes: data
        }
      }

      // Check for singular spelling
      if (data.dataType) {
        data.dataTypes = data.dataType
      }

      // Ensure datatypes is an array
      if (!Array.isArray(data.dataTypes)) {
        data.dataTypes = [data.dataTypes]
      }

      // Normalize data types
      var types = _.uniq((data.dataTypes || []).map(function(type) {
        return type && type.toLowerCase()
      }))

      // Parameter type / source
      var paramType = 'path'
      if (!fromPath) {
        // If not a URI param, check to see if a `post` source
        // was specified, otherwise default to `querystring`
        paramType = (data.paramType && data.paramType === 'post')
          ? 'post'
          : 'querystring'
      }

      // Parameter spec information
      var param = {
        name: name
      , required: fromPath ? true : !!data.required
      , paramType: paramType
      , dataTypes: types
      }

      // If we have a number, check if a min / max value was set
      if (~types.indexOf('number')) {
        if (_.has(data, 'min')) param.min = +data.min;
        if (_.has(data, 'max')) param.max = +data.max;
      }

      // Add in any extra information defined from options
      if (self.options.paramProperties) {
        self.options.paramProperties.forEach(function(prop) {
          if (_.has(data, prop)) {
            param[prop] = data[prop]
          }
        })
      }

      // If we have an object type, check for sub-schemas
      if (~types.indexOf('object') && data.params) {
        param.params = getParams(data.params)
      }

      defs.push(param)
    }
    return defs
  }
function getParams(obj) {
    var defs = []

    for (var name in obj) {
      var data = obj[name]
        , fromPath = ~required.indexOf(name)

      // If string, assume a single data type
      if (typeof data === 'string') {
        data = data.split(',')
      }

      // If array, assume array of data types
      if (Array.isArray(data)) {
        data = obj[name] = {
          dataTypes: data
        }
      }

      // Check for singular spelling
      if (data.dataType) {
        data.dataTypes = data.dataType
      }

      // Ensure datatypes is an array
      if (!Array.isArray(data.dataTypes)) {
        data.dataTypes = [data.dataTypes]
      }

      // Normalize data types
      var types = _.uniq((data.dataTypes || []).map(function(type) {
        return type && type.toLowerCase()
      }))

      // Parameter type / source
      var paramType = 'path'
      if (!fromPath) {
        // If not a URI param, check to see if a `post` source
        // was specified, otherwise default to `querystring`
        paramType = (data.paramType && data.paramType === 'post')
          ? 'post'
          : 'querystring'
      }

      // Parameter spec information
      var param = {
        name: name
      , required: fromPath ? true : !!data.required
      , paramType: paramType
      , dataTypes: types
      }

      // If we have a number, check if a min / max value was set
      if (~types.indexOf('number')) {
        if (_.has(data, 'min')) param.min = +data.min;
        if (_.has(data, 'max')) param.max = +data.max;
      }

      // Add in any extra information defined from options
      if (self.options.paramProperties) {
        self.options.paramProperties.forEach(function(prop) {
          if (_.has(data, prop)) {
            param[prop] = data[prop]
          }
        })
      }

      // If we have an object type, check for sub-schemas
      if (~types.indexOf('object') && data.params) {
        param.params = getParams(data.params)
      }

      defs.push(param)
    }
    return defs
  }
function getParams ( obj ) { var defs = [ ] for ( var name in obj ) { var data = obj [ name ] , fromPath = ~ required . indexOf ( name ) // If string, assume a single data type if ( typeof data === 'string' ) { data = data . split ( ',' ) } // If array, assume array of data types if ( Array . isArray ( data ) ) { data = obj [ name ] = { dataTypes : data } } // Check for singular spelling if ( data . dataType ) { data . dataTypes = data . dataType } // Ensure datatypes is an array if ( ! Array . isArray ( data . dataTypes ) ) { data . dataTypes = [ data . dataTypes ] } // Normalize data types var types = _ . uniq ( ( data . dataTypes || [ ] ) . map ( function ( type ) { return type && type . toLowerCase ( ) } ) ) // Parameter type / source var paramType = 'path' if ( ! fromPath ) { // If not a URI param, check to see if a `post` source // was specified, otherwise default to `querystring` paramType = ( data . paramType && data . paramType === 'post' ) ? 'post' : 'querystring' } // Parameter spec information var param = { name : name , required : fromPath ? true : ! ! data . required , paramType : paramType , dataTypes : types } // If we have a number, check if a min / max value was set if ( ~ types . indexOf ( 'number' ) ) { if ( _ . has ( data , 'min' ) ) param . min = + data . min ; if ( _ . has ( data , 'max' ) ) param . max = + data . max ; } // Add in any extra information defined from options if ( self . options . paramProperties ) { self . options . paramProperties . forEach ( function ( prop ) { if ( _ . has ( data , prop ) ) { param [ prop ] = data [ prop ] } } ) } // If we have an object type, check for sub-schemas if ( ~ types . indexOf ( 'object' ) && data . params ) { param . params = getParams ( data . params ) } defs . push ( param ) } return defs }
Iterate through all defined parameter definitions
Iterate through all defined parameter definitions