@@ -129,7 +129,8 @@ protected Statement createMethodDescriptorVariableDecl(
129
129
Service service ,
130
130
Method protoMethod ,
131
131
VariableExpr methodDescriptorVarExpr ,
132
- Map <String , Message > messageTypes ) {
132
+ Map <String , Message > messageTypes ,
133
+ boolean restNumericEnumsEnabled ) {
133
134
MethodInvocationExpr expr =
134
135
MethodInvocationExpr .builder ()
135
136
.setMethodName ("newBuilder" )
@@ -152,7 +153,11 @@ protected Statement createMethodDescriptorVariableDecl(
152
153
expr = methodMaker .apply ("setHttpMethod" , getHttpMethodTypeExpr (protoMethod )).apply (expr );
153
154
expr = methodMaker .apply ("setType" , getMethodTypeExpr (protoMethod )).apply (expr );
154
155
expr =
155
- methodMaker .apply ("setRequestFormatter" , getRequestFormatterExpr (protoMethod )).apply (expr );
156
+ methodMaker
157
+ .apply (
158
+ "setRequestFormatter" ,
159
+ getRequestFormatterExpr (protoMethod , restNumericEnumsEnabled ))
160
+ .apply (expr );
156
161
expr = methodMaker .apply ("setResponseParser" , setResponseParserExpr (protoMethod )).apply (expr );
157
162
158
163
if (protoMethod .isOperationPollingMethod () || protoMethod .hasLro ()) {
@@ -320,7 +325,7 @@ protected List<MethodDefinition> createGetMethodDescriptorsMethod(
320
325
.build ();
321
326
}
322
327
323
- private List <Expr > getRequestFormatterExpr (Method protoMethod ) {
328
+ private List <Expr > getRequestFormatterExpr (Method protoMethod , boolean restNumericEnumsEnabled ) {
324
329
BiFunction <String , List <Expr >, Function <MethodInvocationExpr , MethodInvocationExpr >>
325
330
methodMaker = getMethodMaker ();
326
331
@@ -351,7 +356,8 @@ private List<Expr> getRequestFormatterExpr(Method protoMethod) {
351
356
protoMethod ,
352
357
extractorVarType ,
353
358
protoMethod .httpBindings ().pathParameters (),
354
- "putPathParam" )))
359
+ "putPathParam" ,
360
+ restNumericEnumsEnabled )))
355
361
.apply (expr );
356
362
357
363
if (!protoMethod .httpBindings ().lowerCamelAdditionalPatterns ().isEmpty ()) {
@@ -387,7 +393,8 @@ private List<Expr> getRequestFormatterExpr(Method protoMethod) {
387
393
protoMethod ,
388
394
extractorVarType ,
389
395
protoMethod .httpBindings ().queryParameters (),
390
- "putQueryParam" )))
396
+ "putQueryParam" ,
397
+ restNumericEnumsEnabled )))
391
398
.apply (expr );
392
399
393
400
extractorVarType = TypeNode .STRING ;
@@ -404,7 +411,8 @@ private List<Expr> getRequestFormatterExpr(Method protoMethod) {
404
411
? protoMethod .httpBindings ().pathParameters ()
405
412
: protoMethod .httpBindings ().bodyParameters (),
406
413
"toBody" ,
407
- asteriskBody )))
414
+ asteriskBody ,
415
+ restNumericEnumsEnabled )))
408
416
.apply (expr );
409
417
expr = methodMaker .apply ("build" , Collections .emptyList ()).apply (expr );
410
418
@@ -771,7 +779,8 @@ private Expr createBodyFieldsExtractorClassInstance(
771
779
TypeNode extractorReturnType ,
772
780
Set <HttpBinding > httpBindingFieldNames ,
773
781
String serializerMethodName ,
774
- boolean asteriskBody ) {
782
+ boolean asteriskBody ,
783
+ boolean restNumericEnumEnabled ) {
775
784
List <Statement > bodyStatements = new ArrayList <>();
776
785
777
786
Expr returnExpr = null ;
@@ -844,6 +853,13 @@ private Expr createBodyFieldsExtractorClassInstance(
844
853
paramsPutArgs .add (ValueExpr .withValue (StringObjectValue .withValue (bodyParamName )));
845
854
paramsPutArgs .add (prevExpr );
846
855
856
+ PrimitiveValue primitiveValue =
857
+ PrimitiveValue .builder ()
858
+ .setType (TypeNode .BOOLEAN )
859
+ .setValue (String .valueOf (restNumericEnumEnabled ))
860
+ .build ();
861
+ paramsPutArgs .add (ValueExpr .withValue (primitiveValue ));
862
+
847
863
returnExpr =
848
864
MethodInvocationExpr .builder ()
849
865
.setExprReferenceExpr (serializerExpr )
@@ -866,7 +882,8 @@ private Expr createFieldsExtractorClassInstance(
866
882
Method method ,
867
883
TypeNode extractorReturnType ,
868
884
Set <HttpBinding > httpBindingFieldNames ,
869
- String serializerMethodName ) {
885
+ String serializerMethodName ,
886
+ boolean restNumericEnumsEnabled ) {
870
887
List <Statement > bodyStatements = new ArrayList <>();
871
888
872
889
VariableExpr fieldsVarExpr =
@@ -980,6 +997,23 @@ private Expr createFieldsExtractorClassInstance(
980
997
}
981
998
}
982
999
1000
+ if (restNumericEnumsEnabled && serializerMethodName .equals ("putQueryParam" )) {
1001
+ ImmutableList .Builder <Expr > paramsPutArgs = ImmutableList .builder ();
1002
+
1003
+ paramsPutArgs .add (fieldsVarExpr );
1004
+ paramsPutArgs .add (ValueExpr .withValue (StringObjectValue .withValue ("$alt" )));
1005
+ paramsPutArgs .add (ValueExpr .withValue (StringObjectValue .withValue ("json;enum-encoding=int" )));
1006
+
1007
+ Expr paramsPutExpr =
1008
+ MethodInvocationExpr .builder ()
1009
+ .setExprReferenceExpr (serializerVarExpr )
1010
+ .setMethodName (serializerMethodName )
1011
+ .setArguments (paramsPutArgs .build ())
1012
+ .setReturnType (extractorReturnType )
1013
+ .build ();
1014
+ bodyStatements .add (ExprStatement .withExpr (paramsPutExpr ));
1015
+ }
1016
+
983
1017
// Overrides FieldsExtractor
984
1018
// (https://github.com/googleapis/gax-java/blob/12b18ee255d3fabe13bb3969df40753b29f830d5/gax-httpjson/src/main/java/com/google/api/gax/httpjson/FieldsExtractor.java).
985
1019
return LambdaExpr .builder ()
0 commit comments