[Android][Volley] add serializeModel support to Android (#3933)

* add serializeModel support to Android

* add test for new android option
This commit is contained in:
wing328
2016-10-06 17:35:33 +08:00
committed by GitHub
parent 515fe33c2c
commit cd6b5fec20
11 changed files with 35 additions and 22 deletions

View File

@@ -29,6 +29,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
protected String projectFolder = "src/main";
protected String sourceFolder = projectFolder + "/java";
protected Boolean useAndroidMavenGradlePlugin = true;
protected Boolean serializableModel = false;
// requestPackage and authPackage are used by the "volley" template/library
protected String requestPackage = "io.swagger.client.request";
@@ -90,6 +91,8 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
cliOptions.add(CliOption.newBoolean(USE_ANDROID_MAVEN_GRADLE_PLUGIN, "A flag to toggle android-maven gradle plugin.")
.defaultValue(Boolean.TRUE.toString()));
cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
supportedLibraries.put("volley", "HTTP client: Volley 1.0.19 (default)");
supportedLibraries.put("httpclient", "HTTP client: Apache HttpClient 4.3.6. JSON processing: Gson 2.3.1. IMPORTANT: Android client using HttpClient is not actively maintained and will be depecreated in the next major release.");
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
@@ -378,6 +381,14 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY));
}
if (additionalProperties.containsKey(CodegenConstants.SERIALIZABLE_MODEL)) {
this.setSerializableModel(Boolean.valueOf(additionalProperties.get(CodegenConstants.SERIALIZABLE_MODEL).toString()));
}
// need to put back serializableModel (boolean) into additionalProperties as value in additionalProperties is string
additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel);
LOGGER.info("CodegenConstants.SERIALIZABLE_MODEL = " + additionalProperties.get(CodegenConstants.SERIALIZABLE_MODEL));
//make api and model doc path available in mustache template
additionalProperties.put( "apiDocPath", apiDocPath );
additionalProperties.put( "modelDocPath", modelDocPath );
@@ -504,6 +515,10 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
this.sourceFolder = sourceFolder;
}
public void setSerializableModel(Boolean serializableModel) {
this.serializableModel = serializableModel;
}
@Override
public String escapeQuotationMark(String input) {
// remove " to avoid code injection