function getFinalParamValue()

in packages/codegen.go/src/fake/servers.ts [1246:1277]


function getFinalParamValue(clientPkg: string, param: go.Parameter, paramValues: Map<string, string>): string {
  let paramValue = paramValues.get(param.name);
  if (!paramValue) {
    // the param didn't require parsing so the "raw" value can be used
    paramValue = getRawParamValue(param);
  }

  // there are a few corner-cases that require some fix-ups

  if ((go.isBodyParameter(param) || go.isFormBodyParameter(param) || go.isFormBodyCollectionParameter(param) || go.isMultipartFormBodyParameter(param)) && go.isTimeType(param.type)) {
    // time types in the body have been unmarshalled into our time helpers thus require a cast to time.Time
    return `time.Time(${paramValue})`;
  } else if (go.isRequiredParameter(param)) {
    // optional params are always in their "final" form
    if (go.isHeaderCollectionParameter(param) || go.isPathCollectionParameter(param) || go.isQueryCollectionParameter(param)) {
      // for required params that are collections of strings, we split them inline.
      // not necessary for optional params as they're already in slice format.
      if (param.collectionFormat !== 'multi' && go.isPrimitiveType(param.type.elementType) && param.type.elementType.typeName === 'string') {
        requiredHelpers.splitHelper = true;
        return `splitHelper(${paramValue}, "${helpers.getDelimiterForCollectionFormat(param.collectionFormat)}")`;
      }
    } else if (go.isHeaderParameter(param) && go.isConstantType(param.type) && param.type.type === 'string') {
      // since headers aren't escaped, we cast required, string-based enums inline
      return `${go.getTypeDeclaration(param.type, clientPkg)}(${paramValue})`;
    }
  } else if (go.isPartialBodyParameter(param)) {
    // use the value from the unmarshaled, intermediate struct type
    return `body.${capitalize(param.name)}`;
  }

  return paramValue;
}