in packages/codegen.go/src/helpers.ts [211:250]
export function formatParamValue(param: go.FormBodyParameter | go.HeaderParameter | go.PathParameter | go.QueryParameter, imports: ImportManager): string {
let paramName = getParamName(param);
if (go.isFormBodyCollectionParameter(param) || go.isHeaderCollectionParameter(param) || go.isPathCollectionParameter(param) || go.isQueryCollectionParameter(param)) {
if (param.collectionFormat === 'multi') {
throw new CodegenError('InternalError', 'multi collection format should have been previously handled');
}
const emitConvertOver = function(paramName: string, format: string): string {
const encodedVar = `encoded${capitalize(paramName)}`;
let content = 'strings.Join(func() []string {\n';
content += `\t\t${encodedVar} := make([]string, len(${paramName}))\n`;
content += `\t\tfor i := 0; i < len(${paramName}); i++ {\n`;
content += `\t\t\t${encodedVar}[i] = ${format}\n\t\t}\n`;
content += `\t\treturn ${encodedVar}\n`;
content += `\t}(), "${separator}")`;
return content;
}
const separator = getDelimiterForCollectionFormat(param.collectionFormat);
if (go.isPrimitiveType(param.type.elementType) && param.type.elementType.typeName === 'string') {
imports.add('strings');
return `strings.Join(${paramName}, "${separator}")`;
} else if (go.isBytesType(param.type.elementType)) {
imports.add('encoding/base64');
imports.add('strings');
return emitConvertOver(param.name, `base64.${formatBytesEncoding(param.type.elementType.encoding)}Encoding.EncodeToString(${param.name}[i])`);
} else if (go.isTimeType(param.type.elementType)) {
imports.add('strings');
return emitConvertOver(param.name, `${param.type.elementType.dateTimeFormat}(${param.name}[i]).String()`);
} else {
imports.add('fmt');
imports.add('strings');
return `strings.Join(strings.Fields(strings.Trim(fmt.Sprint(${paramName}), "[]")), "${separator}")`;
}
} else if (go.isTimeType(param.type) && param.type.dateTimeFormat !== 'timeUnix') {
// for most time types we call methods on time.Time which is why we remove the dereference.
// however, for unix time, we cast to our unixTime helper first so we must keep the dereference.
if (!go.isRequiredParameter(param) && paramName[0] === '*') {
// remove the dereference
paramName = paramName.substring(1);
}
}