1

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?

Giovanni Botta
  • 9,626
  • 5
  • 51
  • 94
  • Please try with the latest version/master (https://github.com/swagger-api/swagger-codegen) as there're a lot of improvements since March. If you still encounter issue, please open a ticket [here](https://github.com/swagger-api/swagger-codegen/issues) – William Cheng Nov 15 '15 at 09:19

0 Answers0