I am using Swagger codegen to generate REST client APIs. I have a supporting class that uses a mustache file that looks like this:
package {{package}};
import {{apiPackage}}.*;
public class MyClient {
private final String basePath, token;
{{#apis}}
private {{className}} i{{className}};
{{/apis}}
public MyClient(String basePath, String token){
this.basePath = basePath;
this.token = token;
}
{{#apis}}
{{className}} get{{className}}(){
if(i{{className}}==null) i{{className}} = new {{className}}(basePath, token);
return i{{className}};
}
{{/apis}}
}
And the generated class looks like this:
package com.mypackage.client;
import com.mypackage.client.api.*;
public class MyClient {
private final String basePath, token;
private AdminApi iAdminApi;
private AppApi iAppApi;
public MyClient(String basePath, String token){
this.basePath = basePath;
this.token = token;
}
AdminApi getAdminApi(){
if(iAdminApi==null) iAdminApi = new AdminApi(basePath, token);
return iAdminApi;
}
AppApi getAppApi(){
if(iAppApi==null) iAppApi = new AppApi(basePath, token);
return iAppApi;
}
}
which is obviously ugly. The rest of the generated code looks good, but I can't seem to figure out why this one class is crappy. Is there something in the mustache file that I am doing wrong?