Skip to content

Commit f3bb4ea

Browse files
authored
Merge pull request #3180 from cbornet/feign_java8
|Feign] Support jsr310 dates in feign client
2 parents 5008de5 + 3e9064b commit f3bb4ea

File tree

19 files changed

+324
-881
lines changed

19 files changed

+324
-881
lines changed

bin/java-petstore-feign.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ fi
2626

2727
# if you've executed sbt assembly previously it will use that instead.
2828
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29-
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -c bin/java-petstore-feign.json -o samples/client/petstore/java/feign -DhideGenerationTimestamp=true"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/Java/libraries/feign -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -c bin/java-petstore-feign.json -o samples/client/petstore/java/feign -DhideGenerationTimestamp=true"
3030

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

modules/swagger-codegen/src/main/resources/Java/libraries/feign/ApiClient.mustache

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuil
99
import com.fasterxml.jackson.databind.DeserializationFeature;
1010
import com.fasterxml.jackson.databind.ObjectMapper;
1111
import com.fasterxml.jackson.databind.SerializationFeature;
12+
{{^java8}}
1213
import com.fasterxml.jackson.datatype.joda.JodaModule;
14+
{{/java8}}
15+
{{#java8}}
16+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
17+
{{/java8}}
1318

1419
import feign.Feign;
1520
import feign.RequestInterceptor;
@@ -131,7 +136,12 @@ public class ApiClient {
131136
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
132137
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
133138
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
139+
{{^java8}}
134140
objectMapper.registerModule(new JodaModule());
141+
{{/java8}}
142+
{{#java8}}
143+
objectMapper.registerModule(new JavaTimeModule());
144+
{{/java8}}
135145
return objectMapper;
136146
}
137147

modules/swagger-codegen/src/main/resources/Java/libraries/feign/build.gradle.mustache

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ if(hasProperty('target') && target == 'android') {
7878
apply plugin: 'java'
7979
apply plugin: 'maven'
8080
81-
sourceCompatibility = JavaVersion.VERSION_1_7
82-
targetCompatibility = JavaVersion.VERSION_1_7
81+
sourceCompatibility = JavaVersion.VERSION_{{^java8}}1_7{{/java8}}{{#java8}}1_8{{/java8}}
82+
targetCompatibility = JavaVersion.VERSION_{{^java8}}1_7{{/java8}}{{#java8}}1_8{{/java8}}
8383

8484
install {
8585
repositories.mavenInstaller {
@@ -95,9 +95,8 @@ if(hasProperty('target') && target == 'android') {
9595

9696
ext {
9797
swagger_annotations_version = "1.5.8"
98-
jackson_version = "2.7.0"
98+
jackson_version = "2.7.5"
9999
feign_version = "8.16.0"
100-
jodatime_version = "2.9.3"
101100
junit_version = "4.12"
102101
oltu_version = "1.0.1"
103102
}
@@ -110,8 +109,7 @@ dependencies {
110109
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
111110
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
112111
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
113-
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
114-
compile "joda-time:joda-time:$jodatime_version"
112+
compile "com.fasterxml.jackson.datatype:jackson-datatype-{{^java8}}joda{{/java8}}{{#java8}}jsr310{{/java8}}:$jackson_version"
115113
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
116114
compile "com.brsanthu:migbase64:2.2"
117115
testCompile "junit:junit:$junit_version"

modules/swagger-codegen/src/main/resources/Java/libraries/feign/build.sbt.mustache

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ lazy val root = (project in file(".")).
1313
"com.netflix.feign" % "feign-core" % "8.16.0" % "compile",
1414
"com.netflix.feign" % "feign-jackson" % "8.16.0" % "compile",
1515
"com.netflix.feign" % "feign-slf4j" % "8.16.0" % "compile",
16-
"com.fasterxml.jackson.core" % "jackson-core" % "2.7.0" % "compile",
17-
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.7.0" % "compile",
18-
"com.fasterxml.jackson.core" % "jackson-databind" % "2.7.0" % "compile",
19-
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.1.5" % "compile",
20-
"joda-time" % "joda-time" % "2.9.3" % "compile",
16+
"com.fasterxml.jackson.core" % "jackson-core" % "2.7.5" % "compile",
17+
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.7.5" % "compile",
18+
"com.fasterxml.jackson.core" % "jackson-databind" % "2.7.5" % "compile",
19+
"com.fasterxml.jackson.datatype" % "jackson-datatype-{{^java8}}joda{{/java8}}{{#java8}}jsr310{{/java8}}" % "2.7.5" % "compile",
2120
"org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile",
2221
"com.brsanthu" % "migbase64" % "2.2" % "compile",
2322
"junit" % "junit" % "4.12" % "test",

modules/swagger-codegen/src/main/resources/Java/libraries/feign/pom.mustache

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,6 @@
9595
</execution>
9696
</executions>
9797
</plugin>
98-
<plugin>
99-
<groupId>org.apache.maven.plugins</groupId>
100-
<artifactId>maven-compiler-plugin</artifactId>
101-
<version>2.3.2</version>
102-
<configuration>
103-
<source>1.7</source>
104-
<target>1.7</target>
105-
</configuration>
106-
</plugin>
10798
</plugins>
10899
</build>
109100
<dependencies>
@@ -148,10 +139,9 @@
148139
</dependency>
149140
<dependency>
150141
<groupId>com.fasterxml.jackson.datatype</groupId>
151-
<artifactId>jackson-datatype-joda</artifactId>
142+
<artifactId>jackson-datatype-{{^java8}}joda{{/java8}}{{#java8}}jsr310{{/java8}}</artifactId>
152143
<version>${jackson-version}</version>
153144
</dependency>
154-
155145
<dependency>
156146
<groupId>org.apache.oltu.oauth2</groupId>
157147
<artifactId>org.apache.oltu.oauth2.client</artifactId>
@@ -167,10 +157,12 @@
167157
</dependency>
168158
</dependencies>
169159
<properties>
160+
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
161+
<maven.compiler.source>${java.version}</maven.compiler.source>
162+
<maven.compiler.target>${java.version}</maven.compiler.target>
170163
<swagger-core-version>1.5.8</swagger-core-version>
171164
<feign-version>8.16.0</feign-version>
172-
<jackson-version>2.7.0</jackson-version>
173-
<jodatime-version>2.9.3</jodatime-version>
165+
<jackson-version>2.7.5</jackson-version>
174166
<junit-version>4.12</junit-version>
175167
<maven-plugin-version>1.0.0</maven-plugin-version>
176168
<oltu-version>1.0.1</oltu-version>

samples/client/petstore/java/feign/.swagger-codegen-ignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

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

1919
# You can also negate patterns with an exclamation (!).
2020
# For example, you can ignore all files in a docs folder with the file extension .md:

samples/client/petstore/java/feign/build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ if(hasProperty('target') && target == 'android') {
9595

9696
ext {
9797
swagger_annotations_version = "1.5.8"
98-
jackson_version = "2.7.0"
98+
jackson_version = "2.7.5"
9999
feign_version = "8.16.0"
100-
jodatime_version = "2.9.3"
101100
junit_version = "4.12"
102101
oltu_version = "1.0.1"
103102
}
@@ -110,8 +109,7 @@ dependencies {
110109
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
111110
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
112111
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
113-
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
114-
compile "joda-time:joda-time:$jodatime_version"
112+
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
115113
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
116114
compile "com.brsanthu:migbase64:2.2"
117115
testCompile "junit:junit:$junit_version"

samples/client/petstore/java/feign/build.sbt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ lazy val root = (project in file(".")).
1313
"com.netflix.feign" % "feign-core" % "8.16.0" % "compile",
1414
"com.netflix.feign" % "feign-jackson" % "8.16.0" % "compile",
1515
"com.netflix.feign" % "feign-slf4j" % "8.16.0" % "compile",
16-
"com.fasterxml.jackson.core" % "jackson-core" % "2.7.0" % "compile",
17-
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.7.0" % "compile",
18-
"com.fasterxml.jackson.core" % "jackson-databind" % "2.7.0" % "compile",
19-
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.1.5" % "compile",
20-
"joda-time" % "joda-time" % "2.9.3" % "compile",
16+
"com.fasterxml.jackson.core" % "jackson-core" % "2.7.5" % "compile",
17+
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.7.5" % "compile",
18+
"com.fasterxml.jackson.core" % "jackson-databind" % "2.7.5" % "compile",
19+
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.7.5" % "compile",
2120
"org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile",
2221
"com.brsanthu" % "migbase64" % "2.2" % "compile",
2322
"junit" % "junit" % "4.12" % "test",

samples/client/petstore/java/feign/pom.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,6 @@
9595
</execution>
9696
</executions>
9797
</plugin>
98-
<plugin>
99-
<groupId>org.apache.maven.plugins</groupId>
100-
<artifactId>maven-compiler-plugin</artifactId>
101-
<version>2.3.2</version>
102-
<configuration>
103-
<source>1.7</source>
104-
<target>1.7</target>
105-
</configuration>
106-
</plugin>
10798
</plugins>
10899
</build>
109100
<dependencies>
@@ -151,7 +142,6 @@
151142
<artifactId>jackson-datatype-joda</artifactId>
152143
<version>${jackson-version}</version>
153144
</dependency>
154-
155145
<dependency>
156146
<groupId>org.apache.oltu.oauth2</groupId>
157147
<artifactId>org.apache.oltu.oauth2.client</artifactId>
@@ -167,10 +157,12 @@
167157
</dependency>
168158
</dependencies>
169159
<properties>
160+
<java.version>1.7</java.version>
161+
<maven.compiler.source>${java.version}</maven.compiler.source>
162+
<maven.compiler.target>${java.version}</maven.compiler.target>
170163
<swagger-core-version>1.5.8</swagger-core-version>
171164
<feign-version>8.16.0</feign-version>
172-
<jackson-version>2.7.0</jackson-version>
173-
<jodatime-version>2.9.3</jodatime-version>
165+
<jackson-version>2.7.5</jackson-version>
174166
<junit-version>4.12</junit-version>
175167
<maven-plugin-version>1.0.0</maven-plugin-version>
176168
<oltu-version>1.0.1</oltu-version>

samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public ApiClient(String[] authNames) {
4141
this();
4242
for(String authName : authNames) {
4343
RequestInterceptor auth;
44-
if (authName == "api_key") {
45-
auth = new ApiKeyAuth("header", "api_key");
46-
} else if (authName == "petstore_auth") {
44+
if (authName == "petstore_auth") {
4745
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
46+
} else if (authName == "api_key") {
47+
auth = new ApiKeyAuth("header", "api_key");
4848
} else {
4949
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
5050
}

0 commit comments

Comments
 (0)