export function getMethodParameters()

in packages/codegen.go/src/helpers.ts [131:183]


export function getMethodParameters(method: go.Method | go.NextPageMethod, paramsFilter?: (p: Array<go.Parameter>) => Array<go.Parameter>): Array<go.Parameter | go.ParameterGroup> {
  const params = new Array<go.Parameter>();
  const paramGroups = new Array<go.ParameterGroup>();
  let methodParams = method.parameters;
  if (paramsFilter) {
    methodParams = paramsFilter(methodParams);
  }
  for (const param of values(methodParams)) {
    if (param.location === 'client') {
      // client params are passed via the receiver
      // must check before param group as client params can be grouped
      continue;
    } else if (param.group) {
      // param groups will be added after individual params
      if (!paramGroups.includes(param.group)) {
        paramGroups.push(param.group);
      }
    } else if (go.isLiteralValue(param.type)) {
      // don't generate a parameter for a constant
      // NOTE: this check must come last as non-required optional constants
      // in header/query params get dumped into the optional params group
      continue;
    } else {
      params.push(param);
    }
  }
  // move global optional params to the end of the slice
  params.sort(sortParametersByRequired);
  // add any parameter groups.  optional groups go last
  paramGroups.sort((a: go.ParameterGroup, b: go.ParameterGroup) => {
    if (a.required === b.required) {
      return 0;
    }
    if (a.required && !b.required) {
      return -1;
    }
    return 1;
  });
  // add the optional param group last if it's not already in the list.
  if (go.isMethod(method)) {
    if (!values(paramGroups).any(gp => { return gp.groupName === method.optionalParamsGroup.groupName; })) {
      paramGroups.push(method.optionalParamsGroup);
    }
  }
  const combined = new Array<go.Parameter | go.ParameterGroup>();
  for (const param of params) {
    combined.push(param);
  }
  for (const paramGroup of paramGroups) {
    combined.push(paramGroup);
  }
  return combined;
}