def find_parameter(params, key_param):
  """
  Find a parameter in params that matches key_param. If key_param is of type 'body', this
  method looks for a matching 'body' parameter among params. Otherwise, it matches up
  parameters by name.

  Args:
    params - A list of parameters
    key_param - A Swagger parameter description (dictionary)

  Returns:
    A parameter that matches key_param, or None if nothing found
  """
  if not params:
    return None
  if key_param['paramType'] == 'body':
    for param in params:
      if param['paramType'] == 'body':
        return param
    return None
  for param in params:
    if param['name'] == key_param['name']:
      return param
  return None