Merge pull request #1927 from xhh/java-imports

[Java] Improve imports in api/models of Java clients
This commit is contained in:
wing328 2016-02-22 11:02:05 +08:00
commit 508ae51f84
31 changed files with 129 additions and 42 deletions

View File

@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import java.util.regex.Pattern;
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
@SuppressWarnings("hiding")
@ -201,6 +202,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
additionalProperties.put(FULL_JAVA_UTIL, fullJavaUtil);
additionalProperties.put("javaUtilPrefix", javaUtilPrefix);
importMapping.put("List", "java.util.List");
if (fullJavaUtil) {
typeMapping.put("array", "java.util.List");
typeMapping.put("map", "java.util.Map");
@ -532,6 +535,12 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
}
}
if ("array".equals(property.containerType)) {
model.imports.add("ArrayList");
} else if ("map".equals(property.containerType)) {
model.imports.add("HashMap");
}
if(!BooleanUtils.toBoolean(model.isEnum)) {
// needed by all pojos, but not enums
model.imports.add("ApiModelProperty");
@ -618,6 +627,17 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
// Remove imports of List, ArrayList, Map and HashMap as they are
// imported in the template already.
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
Pattern pattern = Pattern.compile("java\\.util\\.(List|ArrayList|Map|HashMap)");
for (Iterator<Map<String, String>> itr = imports.iterator(); itr.hasNext();) {
String _import = itr.next().get("import");
if (pattern.matcher(_import).matches()) {
itr.remove();
}
}
if(usesAnyRetrofitLibrary()) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
if (operations != null) {

View File

@ -11,7 +11,10 @@ import {{invokerPackage}}.Pair;
{{/imports}}
{{^fullJavaUtil}}
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
{{>generatedAnnotation}}

View File

@ -5,7 +5,11 @@ import {{invokerPackage}}.ApiClient;
{{#imports}}import {{import}};
{{/imports}}
{{^fullJavaUtil}}import java.util.*;
{{^fullJavaUtil}}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
import feign.*;

View File

@ -11,7 +11,10 @@ import javax.ws.rs.core.GenericType;
{{/imports}}
{{^fullJavaUtil}}
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
{{>generatedAnnotation}}

View File

@ -22,7 +22,10 @@ import java.io.IOException;
import java.lang.reflect.Type;
{{^fullJavaUtil}}
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
{{#operations}}

View File

@ -10,7 +10,10 @@ import retrofit.mime.*;
{{/imports}}
{{^fullJavaUtil}}
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
{{#operations}}

View File

@ -12,7 +12,10 @@ import okhttp3.RequestBody;
{{/imports}}
{{^fullJavaUtil}}
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
{{#operations}}

View File

@ -10,7 +10,10 @@ import io.swagger.client.Pair;
import io.swagger.client.model.Pet;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:20.498+08:00")
public class PetApi {

View File

@ -7,10 +7,12 @@ import io.swagger.client.ApiClient;
import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import java.util.Map;
import io.swagger.client.model.Order;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:20.498+08:00")
public class StoreApi {

View File

@ -8,9 +8,11 @@ import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.model.User;
import java.util.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-12T18:48:10.013-08:00")
public class UserApi {

View File

@ -7,7 +7,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;
import java.util.ArrayList;
import java.util.List;

View File

@ -5,7 +5,10 @@ import io.swagger.client.ApiClient;
import io.swagger.client.model.Pet;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import feign.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:23.375+08:00")

View File

@ -2,10 +2,12 @@ package io.swagger.client.api;
import io.swagger.client.ApiClient;
import java.util.Map;
import io.swagger.client.model.Order;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import feign.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-01-11T21:48:33.457Z")

View File

@ -3,9 +3,11 @@ package io.swagger.client.api;
import io.swagger.client.ApiClient;
import io.swagger.client.model.User;
import java.util.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import feign.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-01-11T21:48:33.457Z")

View File

@ -7,7 +7,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;
import java.util.ArrayList;
import java.util.List;

View File

@ -10,7 +10,10 @@ import javax.ws.rs.core.GenericType;
import io.swagger.client.model.Pet;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:21.885+08:00")
public class PetApi {

View File

@ -7,10 +7,12 @@ import io.swagger.client.Pair;
import javax.ws.rs.core.GenericType;
import java.util.Map;
import io.swagger.client.model.Order;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:21.885+08:00")
public class StoreApi {

View File

@ -8,9 +8,11 @@ import io.swagger.client.Pair;
import javax.ws.rs.core.GenericType;
import io.swagger.client.model.User;
import java.util.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-01-28T16:23:25.238+01:00")
public class UserApi {

View File

@ -7,7 +7,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;
import java.util.ArrayList;
import java.util.List;

View File

@ -21,7 +21,10 @@ import io.swagger.client.model.Pet;
import java.io.File;
import java.lang.reflect.Type;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PetApi {
private ApiClient apiClient;

View File

@ -17,11 +17,13 @@ import com.squareup.okhttp.Response;
import java.io.IOException;
import java.util.Map;
import io.swagger.client.model.Order;
import java.lang.reflect.Type;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class StoreApi {
private ApiClient apiClient;

View File

@ -18,10 +18,12 @@ import com.squareup.okhttp.Response;
import java.io.IOException;
import io.swagger.client.model.User;
import java.util.*;
import java.lang.reflect.Type;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class UserApi {
private ApiClient apiClient;

View File

@ -5,7 +5,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.SerializedName;

View File

@ -9,7 +9,10 @@ import retrofit.mime.*;
import io.swagger.client.model.Pet;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface PetApi {

View File

@ -6,10 +6,12 @@ import retrofit.Callback;
import retrofit.http.*;
import retrofit.mime.*;
import java.util.Map;
import io.swagger.client.model.Order;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface StoreApi {

View File

@ -7,9 +7,11 @@ import retrofit.http.*;
import retrofit.mime.*;
import io.swagger.client.model.User;
import java.util.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface UserApi {

View File

@ -5,7 +5,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.SerializedName;

View File

@ -11,7 +11,10 @@ import okhttp3.RequestBody;
import io.swagger.client.model.Pet;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface PetApi {

View File

@ -8,10 +8,12 @@ import retrofit2.http.*;
import okhttp3.RequestBody;
import java.util.Map;
import io.swagger.client.model.Order;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface StoreApi {

View File

@ -9,9 +9,11 @@ import retrofit2.http.*;
import okhttp3.RequestBody;
import io.swagger.client.model.User;
import java.util.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface UserApi {

View File

@ -5,7 +5,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.SerializedName;