Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -90,6 +91,8 @@ public AndroidClientCodegen() {
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");
Expand Down Expand Up @@ -378,6 +381,14 @@ public void processOpts() {
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 );
Expand Down Expand Up @@ -504,6 +515,10 @@ public void setSourceFolder(String sourceFolder) {
this.sourceFolder = sourceFolder;
}

public void setSerializableModel(Boolean serializableModel) {
this.serializableModel = serializableModel;
}

@Override
public String escapeQuotationMark(String input) {
// remove " to avoid code injection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ package {{package}};

{{#imports}}import {{import}};
{{/imports}}

import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;
{{#serializableModel}}
import java.io.Serializable;
{{/serializableModel}}
{{#models}}

{{#model}}{{#description}}
{{#model}}
{{#description}}
/**
* {{description}}
**/{{/description}}
**/
{{/description}}
@ApiModel(description = "{{{description}}}")
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#serializableModel}}implements Serializable {{/serializableModel}}{
{{#vars}}{{#isEnum}}
public enum {{datatypeWithEnum}} {
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ protected void setExpectations() {
times = 1;
clientCodegen.setLibrary(AndroidClientOptionsProvider.LIBRARY_VALUE);
times = 1;
clientCodegen.setSerializableModel(Boolean.valueOf(AndroidClientOptionsProvider.SERIALIZABLE_MODEL_VALUE));
times = 1;
}};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class AndroidClientOptionsProvider implements OptionsProvider {
public static final String SOURCE_FOLDER_VALUE = "src/main/java/test";
public static final String ANDROID_MAVEN_GRADLE_PLUGIN_VALUE = "true";
public static final String LIBRARY_VALUE = "httpclient";
public static final String SERIALIZABLE_MODEL_VALUE = "false";

@Override
public String getLanguage() {
Expand All @@ -39,6 +40,7 @@ public Map<String, String> createOptions() {
.put(CodegenConstants.SOURCE_FOLDER, SOURCE_FOLDER_VALUE)
.put(AndroidClientCodegen.USE_ANDROID_MAVEN_GRADLE_PLUGIN, ANDROID_MAVEN_GRADLE_PLUGIN_VALUE)
.put(CodegenConstants.LIBRARY, LIBRARY_VALUE)
.put(CodegenConstants.SERIALIZABLE_MODEL, SERIALIZABLE_MODEL_VALUE)
.build();
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/android/volley/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Name | Type | Description | Notes

### Authorization

[petstore_auth](../README.md#petstore_auth), [api_key](../README.md#api_key)
[api_key](../README.md#api_key), [petstore_auth](../README.md#petstore_auth)

### HTTP request headers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public Pet getPetById (Long petId) throws TimeoutException, ExecutionException,
// normal form params
}

String[] authNames = new String[] { "petstore_auth", "api_key" };
String[] authNames = new String[] { "api_key", "petstore_auth" };

try {
String localVarResponse = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
Expand Down Expand Up @@ -693,7 +693,7 @@ public void getPetById (Long petId, final Response.Listener<Pet> responseListene
// normal form params
}

String[] authNames = new String[] { "petstore_auth", "api_key" };
String[] authNames = new String[] { "api_key", "petstore_auth" };

try {
apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@

package io.swagger.client.model;


import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;


@ApiModel(description = "")
public class Category {
public class Category {

@SerializedName("id")
private Long id = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
package io.swagger.client.model;

import java.util.Date;

import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;


@ApiModel(description = "")
public class Order {
public class Order {

@SerializedName("id")
private Long id = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
import io.swagger.client.model.Category;
import io.swagger.client.model.Tag;
import java.util.*;

import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;


@ApiModel(description = "")
public class Pet {
public class Pet {

@SerializedName("id")
private Long id = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@

package io.swagger.client.model;


import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;


@ApiModel(description = "")
public class Tag {
public class Tag {

@SerializedName("id")
private Long id = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@

package io.swagger.client.model;


import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;


@ApiModel(description = "")
public class User {
public class User {

@SerializedName("id")
private Long id = null;
Expand Down