@@ -145,14 +145,13 @@ protected static void addOptionalAndConstantVariables(JavaBlock function, Client
145
145
// parameter is scoped to the client, hence no local variable instantiation for it.
146
146
continue ;
147
147
}
148
-
148
+ final IType parameterClientType = parameter . getClientType ();
149
149
IType parameterWireType ;
150
150
if (parameter .isNullable ()) {
151
151
parameterWireType = parameter .getWireType ().asNullable ();
152
152
} else {
153
153
parameterWireType = parameter .getWireType ();
154
154
}
155
- final IType parameterClientType = parameter .getClientType ();
156
155
157
156
// TODO (alzimmer): There are a few similar transforms like this but they all have slight nuances on output.
158
157
// This always turns ArrayType and ListType into String, the case further down this file may not.
@@ -320,33 +319,44 @@ protected static void applyParameterTransformations(JavaBlock function, ClientMe
320
319
protected static void convertClientTypesToWireTypes (JavaBlock function , ClientMethod clientMethod ) {
321
320
final List <ProxyMethodParameter > proxyMethodParameters = clientMethod .getProxyMethod ().getParameters ();
322
321
for (ProxyMethodParameter parameter : proxyMethodParameters ) {
323
- IType parameterWireType = parameter .getWireType ();
322
+ final RequestParameterLocation location = parameter .getRequestParameterLocation ();
323
+ final IType parameterClientType = parameter .getClientType ();
324
324
325
+ IType parameterWireType ;
325
326
if (parameter .isNullable ()) {
326
- parameterWireType = parameterWireType .asNullable ();
327
+ parameterWireType = parameter .getWireType ().asNullable ();
328
+ } else {
329
+ parameterWireType = parameter .getWireType ();
327
330
}
328
331
329
- IType parameterClientType = parameter .getClientType ();
330
-
331
- // TODO (alzimmer): Reconcile the logic here with that earlier in the file.
332
- // This check parameter explosion but earlier in the file it doesn't.
333
- if (parameterWireType != ClassType .BASE_64_URL
334
- && parameter .getRequestParameterLocation () != RequestParameterLocation .BODY
335
- // && parameter.getRequestParameterLocation() != RequestParameterLocation.FormData &&
336
- && (parameterClientType instanceof ArrayType || parameterClientType instanceof IterableType )) {
337
- parameterWireType = (parameter .getExplode ()) ? new ListType (ClassType .STRING ) : ClassType .STRING ;
332
+ if (location != RequestParameterLocation .BODY ) {
333
+ if (parameterClientType == ArrayType .BYTE_ARRAY ) {
334
+ if (parameterWireType != ClassType .BASE_64_URL ) {
335
+ // A byte[] with wire-type not as Base64-encoded URL is converted to Base64-encoded 'String'.
336
+ // Refer byteArrayToBase64Encoded(..)
337
+ parameterWireType = ClassType .STRING ;
338
+ }
339
+ } else if (parameterClientType instanceof IterableType ) {
340
+ if (!parameter .getExplode ()) {
341
+ // Iterable gets converted to a delimited 'String' of wire values.
342
+ // Refer iterableToDelimitedStringOfWireValues(..)
343
+ parameterWireType = ClassType .STRING ;
344
+ } else {
345
+ // Iterable gets converted to 'List<String>'.
346
+ // Refer iterableToWireStringValuesList(..)'
347
+ parameterWireType = new ListType (ClassType .STRING );
348
+ }
349
+ }
338
350
}
339
351
340
- // If the wire type and client type are the same there is no conversion needed.
341
352
if (parameterWireType == parameterClientType ) {
353
+ // If the wire type and client type are the same there is no conversion needed.
342
354
continue ;
343
355
}
344
356
345
- String parameterName = parameter .getParameterReference ();
346
- String parameterWireName = parameter .getParameterReferenceConverted ();
347
-
357
+ final String parameterName = parameter .getParameterReference ();
358
+ final String parameterWireName = parameter .getParameterReferenceConverted ();
348
359
final boolean alwaysNull = clientMethod .getOnlyRequiredParameters () && !parameter .isRequired ();
349
- final RequestParameterLocation location = parameter .getRequestParameterLocation ();
350
360
351
361
boolean addedConversion = false ;
352
362
if (location != RequestParameterLocation .BODY ) {
@@ -355,7 +365,7 @@ protected static void convertClientTypesToWireTypes(JavaBlock function, ClientMe
355
365
if (alwaysNull ) {
356
366
function .line ("%s %s = %s;" , parameterWireType , parameterWireName , "null" );
357
367
} else {
358
- final String expression = byteArrayToBase64UrlEncodedString (parameterName , parameterWireType );
368
+ final String expression = byteArrayToBase64Encoded (parameterName , parameterWireType );
359
369
function .line ("%s %s = %s;" , parameterWireType , parameterWireName , expression );
360
370
}
361
371
addedConversion = true ;
@@ -552,17 +562,20 @@ private static String iterableToWireStringValuesList(String parameterName, boole
552
562
}
553
563
554
564
/**
555
- * Obtain the Java code that converts a parameter of type byte[] to a Base64 URL encoded string.
565
+ * Obtain the Java code that converts a parameter of type byte[] to Base64 encoded form ( encoded as string or url) .
556
566
*
557
567
* @param parameterName the name of the byte[] parameter to convert.
558
- * @param wireType the wire type of the parameter, used to determine the method to call for encoding .
559
- * @return Java code that converts a byte[] parameter to a Base64 URL encoded string .
568
+ * @param wireType the wire type of the parameter, used to determine whether to encode as a string or url .
569
+ * @return Java code that converts a byte[] parameter to Base64 encoded form .
560
570
*/
561
- private static String byteArrayToBase64UrlEncodedString (String parameterName , IType wireType ) {
562
- final String methodCall = (wireType == ClassType .STRING )
563
- ? "Base64Util.encodeToString"
564
- : (ClassType .BASE_64_URL .getName () + ".encode" );
565
- return methodCall + "(" + parameterName + ")" ;
571
+ private static String byteArrayToBase64Encoded (String parameterName , IType wireType ) {
572
+ if ((wireType == ClassType .STRING )) {
573
+ // byte[] to Base64-encoded String.
574
+ return "Base64Util.encodeToString" + "(" + parameterName + ")" ;
575
+ } else {
576
+ // byte[] to Base64-encoded URL.
577
+ return ClassType .BASE_64_URL .getName () + ".encode" + "(" + parameterName + ")" ;
578
+ }
566
579
}
567
580
568
581
private static boolean addSpecialHeadersToRequestOptions (JavaBlock function , ClientMethod clientMethod ) {
0 commit comments