88import java .lang .annotation .Annotation ;
99import java .lang .reflect .*;
1010import java .util .*;
11- import javax .ws .rs .core .Application ;
1211
1312
1413/**
@@ -54,12 +53,15 @@ public TsModel javaToTypeScript(Model model) {
5453 final TsType optionsType = settings .restOptionsType != null
5554 ? new TsType .VerbatimType (settings .restOptionsType )
5655 : null ;
56+ final TsType .GenericVariableType optionsGenericVariable = settings .restOptionsTypeIsGeneric
57+ ? new TsType .GenericVariableType (settings .restOptionsType )
58+ : null ;
5759
5860 if (settings .generateJaxrsApplicationInterface ) {
59- tsModel = createJaxrsInterfaces (symbolTable , tsModel , jaxrsApplication , responseSymbol , optionsType );
61+ tsModel = createJaxrsInterfaces (symbolTable , tsModel , jaxrsApplication , responseSymbol , optionsGenericVariable , optionsType );
6062 }
6163 if (settings .generateJaxrsApplicationClient ) {
62- tsModel = createJaxrsClients (symbolTable , tsModel , jaxrsApplication , responseSymbol , optionsType );
64+ tsModel = createJaxrsClients (symbolTable , tsModel , jaxrsApplication , responseSymbol , optionsGenericVariable , optionsType );
6365 }
6466 }
6567
@@ -315,20 +317,24 @@ private Symbol createJaxrsResponseType(SymbolTable symbolTable, TsModel tsModel)
315317 return responseSymbol ;
316318 }
317319
318- private TsModel createJaxrsInterfaces (SymbolTable symbolTable , TsModel tsModel , JaxrsApplicationModel jaxrsApplication , Symbol responseSymbol , TsType optionsType ) {
320+ private TsModel createJaxrsInterfaces (SymbolTable symbolTable , TsModel tsModel , JaxrsApplicationModel jaxrsApplication ,
321+ Symbol responseSymbol , TsType .GenericVariableType optionsGenericVariable , TsType optionsType ) {
322+ final List <TsType .GenericVariableType > typeParameters = Utils .listFromNullable (optionsGenericVariable );
319323 final Map <Symbol , List <TsMethodModel >> groupedMethods = processJaxrsMethods (jaxrsApplication , symbolTable , null , responseSymbol , optionsType , false );
320324 for (Map .Entry <Symbol , List <TsMethodModel >> entry : groupedMethods .entrySet ()) {
321- final TsBeanModel interfaceModel = new TsBeanModel (null , TsBeanCategory .Service , false , entry .getKey (), null , null , null , null , null , null , entry .getValue (), null );
325+ final TsBeanModel interfaceModel = new TsBeanModel (null , TsBeanCategory .Service , false , entry .getKey (), typeParameters , null , null , null , null , null , entry .getValue (), null );
322326 tsModel .getBeans ().add (interfaceModel );
323327 }
324328 return tsModel ;
325329 }
326330
327- private TsModel createJaxrsClients (SymbolTable symbolTable , TsModel tsModel , JaxrsApplicationModel jaxrsApplication , Symbol responseSymbol , TsType optionsType ) {
331+ private TsModel createJaxrsClients (SymbolTable symbolTable , TsModel tsModel , JaxrsApplicationModel jaxrsApplication ,
332+ Symbol responseSymbol , TsType .GenericVariableType optionsGenericVariable , TsType optionsType ) {
328333 final Symbol httpClientSymbol = symbolTable .getSyntheticSymbol ("HttpClient" );
334+ final List <TsType .GenericVariableType > typeParameters = Utils .listFromNullable (optionsGenericVariable );
329335
330336 // HttpClient interface
331- tsModel .getBeans ().add (new TsBeanModel (null , TsBeanCategory .ServicePrerequisite , false , httpClientSymbol , null , null , null , null , null , null , Arrays .asList (
337+ tsModel .getBeans ().add (new TsBeanModel (null , TsBeanCategory .ServicePrerequisite , false , httpClientSymbol , typeParameters , null , null , null , null , null , Arrays .asList (
332338 new TsMethodModel ("request" , new TsType .GenericReferenceType (responseSymbol , TsType .Any ), Arrays .asList (
333339 new TsParameterModel ("requestConfig" , new TsType .ObjectType (
334340 new TsProperty ("method" , TsType .String ),
@@ -341,8 +347,11 @@ private TsModel createJaxrsClients(SymbolTable symbolTable, TsModel tsModel, Jax
341347 ), null ));
342348
343349 // application client classes
350+ final TsType .ReferenceType httpClientType = optionsGenericVariable != null
351+ ? new TsType .GenericReferenceType (httpClientSymbol , optionsGenericVariable )
352+ : new TsType .ReferenceType (httpClientSymbol );
344353 final TsConstructorModel constructor = new TsConstructorModel (
345- Arrays .asList (new TsParameterModel (TsAccessibilityModifier .Protected , "httpClient" , new TsType . ReferenceType ( httpClientSymbol ) )),
354+ Arrays .asList (new TsParameterModel (TsAccessibilityModifier .Protected , "httpClient" , httpClientType )),
346355 Collections .<TsStatement >emptyList (),
347356 null
348357 );
@@ -351,7 +360,7 @@ private TsModel createJaxrsClients(SymbolTable symbolTable, TsModel tsModel, Jax
351360 for (Map .Entry <Symbol , List <TsMethodModel >> entry : groupedMethods .entrySet ()) {
352361 final Symbol symbol = settings .generateJaxrsApplicationInterface ? symbolTable .addSuffixToSymbol (entry .getKey (), "Client" ) : entry .getKey ();
353362 final TsType interfaceType = settings .generateJaxrsApplicationInterface ? new TsType .ReferenceType (entry .getKey ()) : null ;
354- final TsBeanModel clientModel = new TsBeanModel (null , TsBeanCategory .Service , true , symbol , null , null , null ,
363+ final TsBeanModel clientModel = new TsBeanModel (null , TsBeanCategory .Service , true , symbol , typeParameters , null , null ,
355364 Utils .listFromNullable (interfaceType ), null , constructor , entry .getValue (), null );
356365 tsModel .getBeans ().add (clientModel );
357366 }
0 commit comments