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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion bin/java-petstore-all.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# update java petstore for all supported http libraries

./bin/java-petstore.sh
./bin/java-petstore-jersey1.sh
./bin/java-petstore-jersey2.sh
./bin/java-petstore-feign.sh
./bin/java-petstore-okhttp-gson.sh
Expand Down
8 changes: 4 additions & 4 deletions bin/java-petstore.sh → bin/java-petstore-jersey1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -o samples/client/petstore/java/default -DhideGenerationTimestamp=true"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -o samples/client/petstore/java/jersey1 -DhideGenerationTimestamp=true --library=jersey1"

echo "Removing files and folders under samples/client/petstore/java/default/src/main"
rm -rf samples/client/petstore/java/default/src/main
find samples/client/petstore/java/default -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
echo "Removing files and folders under samples/client/petstore/java/jersey1/src/main"
rm -rf samples/client/petstore/java/jersey1/src/main
find samples/client/petstore/java/jersey1 -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
java $JAVA_OPTS -jar $executable $ags
Empty file modified bin/java8-petstore-jersey2.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ public JavaClientCodegen() {

cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));

supportedLibraries.put(DEFAULT_LIBRARY, "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0");
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0");
supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.16.0. JSON processing: Jackson 2.7.0");
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.22.2. JSON processing: Jackson 2.7.0");
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.6.2");
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.2.0. JSON processing: Gson 2.6.1 (Retrofit 2.0.2). Enable the RxJava adapter using '-DuseRxJava=true'. (RxJava 1.1.3)");

CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
library.setEnum(supportedLibraries);
library.setDefault(DEFAULT_LIBRARY);
cliOptions.add(library);
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
libraryOption.setEnum(supportedLibraries);
libraryOption.setDefault("okhttp-gson");
cliOptions.add(libraryOption);

setLibrary("okhttp-gson");

}

Expand Down Expand Up @@ -76,6 +78,7 @@ public void processOpts() {
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
writeOptional(outputFolder, new SupportingFile("build.gradle.mustache", "", "build.gradle"));
writeOptional(outputFolder, new SupportingFile("build.sbt.mustache", "", "build.sbt"));
writeOptional(outputFolder, new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
writeOptional(outputFolder, new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
writeOptional(outputFolder, new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
Expand All @@ -95,11 +98,6 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));

if (!StringUtils.isEmpty(getLibrary())) {
//TODO: add sbt support to default client
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
}

//TODO: add doc to retrofit1 and feign
if ( "feign".equals(getLibrary()) || "retrofit".equals(getLibrary()) ){
modelDocTemplateFiles.remove("model_doc.mustache");
Expand All @@ -116,7 +114,7 @@ public void processOpts() {
if ("feign".equals(getLibrary())) {
supportingFiles.add(new SupportingFile("FormAwareEncoder.mustache", invokerFolder, "FormAwareEncoder.java"));
additionalProperties.put("jackson", "true");
} else if ("okhttp-gson".equals(getLibrary())) {
} else if ("okhttp-gson".equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) {
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
Expand All @@ -131,8 +129,10 @@ public void processOpts() {
} else if("jersey2".equals(getLibrary())) {
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
additionalProperties.put("jackson", "true");
} else if(StringUtils.isEmpty(getLibrary())) {
} else if("jersey1".equals(getLibrary())) {
additionalProperties.put("jackson", "true");
} else {
LOGGER.error("Unknown library option (-l/--library): " + getLibrary());
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
if(!BooleanUtils.toBoolean(model.isEnum)) {
final String lib = getLibrary();
//final String lib = getLibrary();
//Needed imports for Jackson based libraries
if(additionalProperties.containsKey("jackson")) {
model.imports.add("JsonProperty");
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ public class ApiClient {
* @throws ApiException If fail to deserialize response body, i.e. cannot read response body
* or the Content-Type of the response is not supported.
*/
@SuppressWarnings("unchecked")
public <T> T deserialize(Response response, Type returnType) throws ApiException {
if (response == null || returnType == null) {
return null;
Expand Down Expand Up @@ -984,6 +985,7 @@ public class ApiClient {
* @param returnType Return type
* @param callback ApiCallback
*/
@SuppressWarnings("unchecked")
public <T> void executeAsync(Call call, final Type returnType, final ApiCallback<T> callback) {
call.enqueue(new Callback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class JSON {
* @param returnType The type to deserialize inot
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public <T> T deserialize(String body, Type returnType) {
try {
if (apiClient.isLenientOnJson()) {
Expand Down Expand Up @@ -287,4 +288,4 @@ class LocalDateTypeAdapter extends TypeAdapter<LocalDate> {
}
}
}
{{/java8}}
{{/java8}}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public void testSkipOverwrite() throws Exception {

final Swagger swagger = new SwaggerParser().read("src/test/resources/petstore.json");
CodegenConfig codegenConfig = new JavaClientCodegen();
codegenConfig.setLibrary("jersey1");
codegenConfig.setOutputDir(output.getAbsolutePath());

ClientOptInput clientOptInput = new ClientOptInput().opts(new ClientOpts()).swagger(swagger).config(codegenConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public void getOptionsTest() throws ApiException {
assertNotNull(options);
final CliOption opt = options.get(CodegenConstants.LIBRARY);
assertNotNull(opt);
assertEquals(opt.getDefault(), JavaClientCodegen.DEFAULT_LIBRARY);
assertEquals(opt.getDefault(), "okhttp-gson");
}
}
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@
</modules>
</profile>
<profile>
<id>java-client</id>
<id>java-client-jersey1</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/java/default</module>
<module>samples/client/petstore/java/jersey1</module>
</modules>
</profile>
<profile>
Expand Down Expand Up @@ -615,7 +615,7 @@
<module>samples/client/petstore/typescript-node/npm</module>
<module>samples/client/petstore/android/volley</module>
<module>samples/client/petstore/clojure</module>
<module>samples/client/petstore/java/default</module>
<module>samples/client/petstore/java/jersey1</module>
<module>samples/client/petstore/java/feign</module>
<module>samples/client/petstore/java/jersey2</module>
<module>samples/client/petstore/java/okhttp-gson</module>
Expand Down

This file was deleted.

This file was deleted.

Loading