Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set Feign version #1005

Merged
merged 4 commits into from
Sep 13, 2018
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
1 change: 1 addition & 0 deletions CI/pom.xml.circleci
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@
<module>samples/client/petstore/scalaz</module>
<module>samples/client/petstore/clojure</module>
<module>samples/client/petstore/java/feign</module>
<module>samples/client/petstore/java/feign10x</module>
<module>samples/client/petstore/java/jersey1</module>
<module>samples/client/petstore/java/jersey2</module>
<module>samples/client/petstore/java/jersey2-java8</module>
Expand Down
1 change: 1 addition & 0 deletions bin/java-petstore-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
./bin/java-petstore-jersey1.sh
./bin/java-petstore-jersey2.sh
./bin/java-petstore-feign.sh
./bin/java-petstore-feign-10x.sh
./bin/java-petstore-okhttp-gson.sh
./bin/java-petstore-okhttp-gson-parcelable.sh
./bin/java-petstore-retrofit.sh
Expand Down
5 changes: 5 additions & 0 deletions bin/java-petstore-feign-10x.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"library": "feign",
"artifactId": "petstore-feign-10x",
"feignVersion": "10.x"
}
40 changes: 40 additions & 0 deletions bin/java-petstore-feign-10x.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"

if [ ! -f "$executable" ]
then
mvn -B clean package
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 -t modules/openapi-generator/src/main/resources/Java/libraries/feign -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-feign-10x.json -o samples/client/petstore/java/feign10x -DhideGenerationTimestamp=true -DbooleanGetterPrefix=is $@"

echo "Removing files and folders under samples/client/petstore/java/feign10x/src/main"
rm -rf samples/client/petstore/java/feign10x/src/main
find samples/client/petstore/java/feign10x -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
java $JAVA_OPTS -jar $executable $ags

# copy additional manually written unit-tests
mkdir samples/client/petstore/java/feign10x/src/test/java/org/openapitools/client

cp CI/samples.ci/client/petstore/java/test-manual/common/StringUtilTest.java samples/client/petstore/java/feign10x/src/test/java/org/openapitools/client/StringUtilTest.java
5 changes: 5 additions & 0 deletions bin/java-petstore-feign-9x.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"library": "feign",
"artifactId": "petstore-feign",
"feignVersion": "9.x"
}
4 changes: 1 addition & 3 deletions bin/java-petstore-feign.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"library": "feign",
"artifactId": "petstore-feign",
"additionalProperties": {
"useFeign10": true
}
"feignVersion": "10.x"
}
4 changes: 2 additions & 2 deletions bin/java-petstore-feign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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 -t modules/openapi-generator/src/main/resources/Java/libraries/feign -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-feign.json -o samples/client/petstore/java/feign -DhideGenerationTimestamp=true -DbooleanGetterPrefix=is $@"
ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/feign -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-feign-9x.json -o samples/client/petstore/java/feign -DhideGenerationTimestamp=true -DbooleanGetterPrefix=is $@"

echo "Removing files and folders under samples/client/petstore/java/feign/src/main"
rm -rf samples/client/petstore/java/feign/src/main
Expand All @@ -37,4 +37,4 @@ java $JAVA_OPTS -jar $executable $ags
# copy additional manually written unit-tests
mkdir samples/client/petstore/java/feign/src/test/java/org/openapitools/client

cp CI/samples.ci/client/petstore/java/test-manual/common/StringUtilTest.java samples/client/petstore/java/feign/src/test/java/org/openapitools/client/StringUtilTest.java
cp CI/samples.ci/client/petstore/java/test-manual/common/StringUtilTest.java samples/client/petstore/java/feign/src/test/java/org/openapitools/client/StringUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String DO_NOT_USE_RX = "doNotUseRx";
public static final String USE_PLAY_WS = "usePlayWS";
public static final String PLAY_VERSION = "playVersion";
public static final String FEIGN_VERSION = "feignVersion";
public static final String PARCELABLE_MODEL = "parcelableModel";
public static final String USE_RUNTIME_EXCEPTION = "useRuntimeException";

public static final String PLAY_24 = "play24";
public static final String PLAY_25 = "play25";
public static final String PLAY_26 = "play26";

public static final String FEIGN_9 = "9.x";
public static final String FEIGN_10 = "10.x";

public static final String FEIGN = "feign";
public static final String GOOGLE_API_CLIENT = "google-api-client";
public static final String JERSEY1 = "jersey1";
Expand All @@ -86,6 +90,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
protected boolean doNotUseRx = true; // backwards compatibility for swagger configs that specify neither rx1 nor rx2 (mustache does not allow for boolean operators so we need this extra field)
protected boolean usePlayWS = false;
protected String playVersion = PLAY_25;
protected String feignVersion = FEIGN_9;
protected boolean parcelableModel = false;
protected boolean useBeanValidation = false;
protected boolean performBeanValidation = false;
Expand All @@ -106,15 +111,16 @@ public JavaClientCodegen() {
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA2, "Whether to use the RxJava2 adapter with the retrofit2 library."));
cliOptions.add(CliOption.newBoolean(PARCELABLE_MODEL, "Whether to generate models for Android that implement Parcelable with the okhttp-gson library."));
cliOptions.add(CliOption.newBoolean(USE_PLAY_WS, "Use Play! Async HTTP client (Play WS API)"));
cliOptions.add(CliOption.newString(PLAY_VERSION, "Version of Play! Framework (possible values \"play24\", \"play25\")"));
cliOptions.add(CliOption.newString(PLAY_VERSION, "Version of Play! Framework (possible values \"play24\", \"play25\" (default), \"play26\")"));
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1 library."));
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception"));
cliOptions.add(CliOption.newBoolean(FEIGN_VERSION, "Version of OpenFeign: '10.x', '9.x' (default)"));

supportedLibraries.put(JERSEY1, "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.8.9. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.9");
supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.9. To enable OpenFeign 10.x, set the 'feignVersion' option to '10.x'");
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.8.9");
supportedLibraries.put(OKHTTP_GSON, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.");
Expand Down Expand Up @@ -147,7 +153,7 @@ public String getName() {

@Override
public String getHelp() {
return "Generates a Java client library.";
return "Generates a Java client library (HTTP lib: Jersey (1.x, 2.x), Retrofit (1.x, 2.x), OpenFeign (9.x, 10.x) and more.";
}

@Override
Expand All @@ -158,6 +164,7 @@ public void processOpts() {

super.processOpts();

// RxJava
if (additionalProperties.containsKey(USE_RX_JAVA) && additionalProperties.containsKey(USE_RX_JAVA2)) {
LOGGER.warn("You specified both RxJava versions 1 and 2 but they are mutually exclusive. Defaulting to v2.");
} else if (additionalProperties.containsKey(USE_RX_JAVA)) {
Expand All @@ -169,6 +176,8 @@ public void processOpts() {
if (!useRxJava && !useRxJava2) {
additionalProperties.put(DO_NOT_USE_RX, true);
}

// Java Play
if (additionalProperties.containsKey(USE_PLAY_WS)) {
this.setUsePlayWS(Boolean.valueOf(additionalProperties.get(USE_PLAY_WS).toString()));
}
Expand All @@ -179,6 +188,20 @@ public void processOpts() {
}
additionalProperties.put(PLAY_VERSION, playVersion);

// OpenFeign
if (additionalProperties.containsKey(FEIGN_VERSION)) {
this.setFeignVersion(additionalProperties.get(FEIGN_VERSION).toString());

if ("10.x".equals(feignVersion)) {
additionalProperties.put("useFeign10", true);
} else if ("9.x".equals(feignVersion)) {
// do nothing as 9.x is the default
} else {
throw new RuntimeException("Ivalid feignOoption '{}'. Must be '10.x' or '9.x'.");
}
}
additionalProperties.put(FEIGN_VERSION, feignVersion);

if (additionalProperties.containsKey(PARCELABLE_MODEL)) {
this.setParcelableModel(Boolean.valueOf(additionalProperties.get(PARCELABLE_MODEL).toString()));
}
Expand Down Expand Up @@ -579,6 +602,10 @@ public void setPlayVersion(String playVersion) {
this.playVersion = playVersion;
}

public void setFeignVersion(String feignVersion) {
this.feignVersion = feignVersion;
}

public void setParcelableModel(boolean parcelableModel) {
this.parcelableModel = parcelableModel;
}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/feign/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ext {
swagger_annotations_version = "1.5.21"
jackson_version = "2.8.7"
threepane_version = "2.6.4"
feign_version = "10.0.1"
feign_version = "9.4.0"
feign_form_version = "2.1.0"
junit_version = "4.12"
oltu_version = "1.0.1"
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/java/feign/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ lazy val root = (project in file(".")).
resolvers += Resolver.mavenLocal,
libraryDependencies ++= Seq(
"io.swagger" % "swagger-annotations" % "1.5.21" % "compile",
"io.github.openfeign" % "feign-core" % "10.0.1" % "compile",
"io.github.openfeign" % "feign-jackson" % "10.0.1" % "compile",
"io.github.openfeign" % "feign-slf4j" % "10.0.1" % "compile",
"io.github.openfeign" % "feign-core" % "9.4.0" % "compile",
"io.github.openfeign" % "feign-jackson" % "9.4.0" % "compile",
"io.github.openfeign" % "feign-slf4j" % "9.4.0" % "compile",
"io.github.openfeign.form" % "feign-form" % "2.1.0" % "compile",
"com.fasterxml.jackson.core" % "jackson-core" % "2.8.7" % "compile",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.8.7" % "compile",
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/feign/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<swagger-annotations-version>1.5.21</swagger-annotations-version>
<feign-version>10.0.1</feign-version>
<feign-version>9.4.0</feign-version>
<feign-form-version>2.1.0</feign-form-version>
<jackson-version>2.8.9</jackson-version>
<jackson-threetenbp-version>2.6.4</jackson-threetenbp-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.oltu.oauth2.common.token.BasicOAuthToken;

import feign.Client;
import feign.Request.HttpMethod;
import feign.Request.Options;
import feign.RequestInterceptor;
import feign.RequestTemplate;
Expand Down Expand Up @@ -93,7 +92,7 @@ public synchronized void updateAccessToken() {
try {
accessTokenResponse = oauthClient.accessToken(tokenRequestBuilder.buildBodyMessage());
} catch (Exception e) {
throw new RetryableException(e.getMessage(), HttpMethod.POST, e, null);
throw new RetryableException(e.getMessage(), e,null);
}
if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) {
setAccessToken(accessTokenResponse.getAccessToken(), accessTokenResponse.getExpiresIn());
Expand Down
21 changes: 21 additions & 0 deletions samples/client/petstore/java/feign10x/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# exclude jar for gradle wrapper
!gradle/wrapper/*.jar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# build files
**/target
target
.gradle
build
23 changes: 23 additions & 0 deletions samples/client/petstore/java/feign10x/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.0-SNAPSHOT
17 changes: 17 additions & 0 deletions samples/client/petstore/java/feign10x/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Generated by: https://openapi-generator.tech
#
language: java
jdk:
- oraclejdk8
- oraclejdk7
before_install:
# ensure gradlew has proper permission
- chmod a+x ./gradlew
script:
# test using maven
- mvn test
# uncomment below to test using gradle
# - gradle test
# uncomment below to test using sbt
# - sbt test
43 changes: 43 additions & 0 deletions samples/client/petstore/java/feign10x/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# petstore-feign

## Requirements

Building the API client library requires [Maven](https://maven.apache.org/) to be installed.

## Installation & Usage

To install the API client library to your local Maven repository, simply execute:

```shell
mvn install
```

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

```shell
mvn deploy
```

Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information.

After the client library is installed/deployed, you can use it in your Maven project by adding the following to your *pom.xml*:

```xml
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>petstore-feign</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>

```

## Recommendation

It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.

## Author




Loading