@@ -4280,14 +4280,19 @@ restAPIMethodReturnBodyClientType is ListType restAPIMethodReturnBodyClientListT
4280
4280
}
4281
4281
4282
4282
IType returnValueTypeArgumentType = ( ( GenericType ) restAPIMethod . ReturnType ) . TypeArguments . Single ( ) ;
4283
+ // TODO: generate anonymous classes for paging
4284
+ IType mapperReturnType = ( ( GenericType ) returnValueTypeArgumentType ) . TypeArguments . Last ( ) ;
4283
4285
4284
4286
string restAPIMethodArgumentList = GetRestAPIMethodArgumentList ( autoRestMethodOrderedRetrofitParameters , settings ) ;
4285
4287
4286
4288
function . Line ( $ "return service.{ restAPIMethod . Name } ({ restAPIMethodArgumentList } )") ;
4287
4289
function . Indent ( ( ) =>
4288
4290
{
4289
4291
function . Text ( ".map(" ) ;
4290
- function . Lambda ( returnValueTypeArgumentType . ToString ( ) , "res" , "res.body()" ) ;
4292
+ function . AnonymousClass ( $ "new Function<{ returnValueTypeArgumentType } , { mapperReturnType } >()", anonymousClass =>
4293
+ {
4294
+ anonymousClass . PublicMethod ( $ "{ mapperReturnType } apply(RestResponse<?, ?> res)", method => method . Return ( "res.body()" ) ) ;
4295
+ } ) ;
4291
4296
function . Line ( ");" ) ;
4292
4297
} ) ;
4293
4298
} ) ;
@@ -4342,12 +4347,18 @@ restAPIMethodReturnBodyClientType is ListType restAPIMethodReturnBodyClientListT
4342
4347
ConvertClientTypesToWireTypes ( function , autoRestMethodRetrofitParameters , methodClientReference , settings ) ;
4343
4348
4344
4349
IType returnValueTypeArgumentType = ( ( GenericType ) restAPIMethod . ReturnType ) . TypeArguments . Single ( ) ;
4350
+ IType mapperReturnType = clientMethod . ReturnValue . Type ;
4351
+
4345
4352
string restAPIMethodArgumentList = GetRestAPIMethodArgumentList ( autoRestMethodOrderedRetrofitParameters , settings ) ;
4346
4353
function . Line ( $ "return service.{ clientMethod . RestAPIMethod . Name } ({ restAPIMethodArgumentList } )") ;
4347
4354
function . Indent ( ( ) =>
4348
4355
{
4349
4356
function . Text ( ".map(" ) ;
4350
- function . Lambda ( returnValueTypeArgumentType . ToString ( ) , "res" , "res.body()" ) ;
4357
+
4358
+ function . AnonymousClass ( $ "new Function<{ returnValueTypeArgumentType } , { mapperReturnType } >()", anonymousClass =>
4359
+ {
4360
+ anonymousClass . PublicMethod ( $ "{ mapperReturnType } apply(RestResponse<?, { mapperReturnType } > res)", method => method . Return ( "res.body()" ) ) ;
4361
+ } ) ;
4351
4362
function . Line ( ")" ) ;
4352
4363
function . Line ( ".toObservable();" ) ;
4353
4364
} ) ;
@@ -4551,16 +4562,27 @@ restAPIMethodReturnBodyClientType is ListType restAPIMethodReturnBodyClientListT
4551
4562
{
4552
4563
GenericType restAPIMethodClientReturnType = ( GenericType ) ConvertToClientType ( restAPIMethod . ReturnType ) ;
4553
4564
IType returnValueTypeArgumentClientType = restAPIMethodClientReturnType . TypeArguments . Single ( ) ;
4565
+ IType mapperReturnType = clientMethod . ReturnValue . Type ;
4554
4566
if ( restAPIMethodReturnBodyClientType != PrimitiveType . Void )
4555
4567
{
4556
4568
function . Text ( $ ".flatMapMaybe(") ;
4557
- function . Lambda ( returnValueTypeArgumentClientType . ToString ( ) , "res" , "res.body() == null ? Maybe.empty() : Maybe.just(res.body())" ) ;
4569
+ function . AnonymousClass ( $ "new Function<{ returnValueTypeArgumentClientType } , { mapperReturnType } >()", anonymousClassBlock =>
4570
+ {
4571
+ anonymousClassBlock . PublicMethod (
4572
+ $ "{ mapperReturnType } apply({ returnValueTypeArgumentClientType } res)",
4573
+ method => method . Return ( $ "res.body() == null ? Maybe.<{ restAPIMethodReturnBodyClientType . AsNullable ( ) } >empty() : Maybe.just(res.body())") ) ;
4574
+ } ) ;
4558
4575
function . Line ( ");" ) ;
4559
4576
}
4560
4577
else if ( isFluentDelete )
4561
4578
{
4562
4579
function . Text ( $ ".flatMapMaybe(") ;
4563
- function . Lambda ( returnValueTypeArgumentClientType . ToString ( ) , "res" , "Maybe.empty()" ) ;
4580
+ function . AnonymousClass ( $ "new Function<{ returnValueTypeArgumentClientType } , { GenericType . Maybe ( ClassType . Void ) } >()", anonymousClassBlock =>
4581
+ {
4582
+ anonymousClassBlock . PublicMethod (
4583
+ $ "{ GenericType . Maybe ( ClassType . Void ) } apply({ returnValueTypeArgumentClientType } res)",
4584
+ method => method . Return ( "Maybe.empty()" ) ) ;
4585
+ } ) ;
4564
4586
function . Line ( ");" ) ;
4565
4587
}
4566
4588
else
@@ -5393,7 +5415,7 @@ private static string GetRestAPIMethodArgumentList(IEnumerable<AutoRestParameter
5393
5415
} ) ;
5394
5416
return string . Join ( ", " , restAPIMethodArguments ) ;
5395
5417
}
5396
-
5418
+
5397
5419
private static string AddClientTypePrefix ( string clientType , JavaSettings settings )
5398
5420
=> string . IsNullOrEmpty ( settings . ClientTypePrefix ) ? clientType : settings . ClientTypePrefix + clientType ;
5399
5421
}
0 commit comments