Skip to content

Commit

Permalink
[Java-client] Add Spring 5 WebClient as new library (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
0v1se authored and jmini committed Jul 4, 2018
1 parent d6e950f commit b90c53d
Show file tree
Hide file tree
Showing 126 changed files with 12,210 additions and 0 deletions.
1 change: 1 addition & 0 deletions CI/pom.xml.circleci
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@
<module>samples/client/petstore/jaxrs-cxf-client</module>
<module>samples/client/petstore/java/resttemplate</module>
<module>samples/client/petstore/java/resttemplate-withXml</module>
<module>samples/client/petstore/java/webclient</module>
<module>samples/client/petstore/java/vertx</module>
<module>samples/client/petstore/java/resteasy</module>
<module>samples/client/petstore/java/google-api-client</module>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ Here is a list of template creators:
* Java (Jersey2): @xhh
* Java (okhttp-gson): @xhh
* Java (RestTemplate): @nbruno
* Java (Spring 5 WebClient): @daonomic
* Java (RESTEasy): @gayathrigs
* Java (Vertx): @lopesmcc
* Java (Google APIs Client Library): @charlescapps
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 @@ -16,6 +16,7 @@
./bin/java-petstore-jersey2-java6.sh
./bin/java-petstore-resttemplate.sh
./bin/java-petstore-resttemplate-withxml.sh
./bin/java-petstore-webclient.sh
./bin/java-petstore-resteasy.sh
./bin/java-petstore-google-api-client.sh
./bin/java-petstore-rest-assured.sh
Expand Down
4 changes: 4 additions & 0 deletions bin/java-petstore-webclient.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"library": "webclient",
"artifactId": "petstore-webclient"
}
45 changes: 45 additions & 0 deletions bin/java-petstore-webclient.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/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 -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-webclient.json -o samples/client/petstore/java/webclient -DhideGenerationTimestamp=true $@"

echo "Removing files and folders under samples/client/petstore/java/webclient/src/main"
rm -rf samples/client/petstore/java/webclient/src/main
find samples/client/petstore/java/webclient -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/webclient/src/test/java/org/openapitools/client
mkdir samples/client/petstore/java/webclient/src/test/java/org/openapitools/client/auth
mkdir samples/client/petstore/java/webclient/src/test/java/org/openapitools/client/model

cp CI/samples.ci/client/petstore/java/test-manual/webclient/ApiClientTest.java samples/client/petstore/java/webclient/src/test/java/org/openapitools/client/ApiClientTest.java
cp CI/samples.ci/client/petstore/java/test-manual/webclient/auth/ApiKeyAuthTest.java samples/client/petstore/java/webclient/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java
cp CI/samples.ci/client/petstore/java/test-manual/webclient/auth/HttpBasicAuthTest.java samples/client/petstore/java/webclient/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java
cp CI/samples.ci/client/petstore/java/test-manual/webclient/model/EnumValueTest.java samples/client/petstore/java/webclient/src/test/java/org/openapitools/client/model/EnumValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String OKHTTP_GSON = "okhttp-gson";
public static final String RESTEASY = "resteasy";
public static final String RESTTEMPLATE = "resttemplate";
public static final String WEBCLIENT = "webclient";
public static final String REST_ASSURED = "rest-assured";
public static final String RETROFIT_1 = "retrofit";
public static final String RETROFIT_2 = "retrofit2";
Expand Down Expand Up @@ -120,6 +121,7 @@ public JavaClientCodegen() {
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.");
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.8.0. JSON processing: Gson 2.6.1 (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)");
supportedLibraries.put(RESTTEMPLATE, "HTTP client: Spring RestTemplate 4.3.9-RELEASE. JSON processing: Jackson 2.8.9");
supportedLibraries.put(WEBCLIENT, "HTTP client: Spring WebClient 5.0.7-RELEASE. JSON processing: Jackson 2.9.5");
supportedLibraries.put(RESTEASY, "HTTP client: Resteasy client 3.1.3.Final. JSON processing: Jackson 2.8.9");
supportedLibraries.put(VERTX, "HTTP client: VertX client 3.2.4. JSON processing: Jackson 2.8.9");
supportedLibraries.put(GOOGLE_API_CLIENT, "HTTP client: Google API client 1.23.0. JSON processing: Jackson 2.8.9");
Expand Down Expand Up @@ -151,6 +153,10 @@ public String getHelp() {

@Override
public void processOpts() {
if (WEBCLIENT.equals(getLibrary()) && "threetenbp".equals(dateLibrary)) {
dateLibrary = "java8";
}

super.processOpts();

if (additionalProperties.containsKey(USE_RX_JAVA) && additionalProperties.containsKey(USE_RX_JAVA2)) {
Expand Down Expand Up @@ -280,6 +286,8 @@ public void processOpts() {
} else if (RESTTEMPLATE.equals(getLibrary())) {
additionalProperties.put("jackson", "true");
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
} else if (WEBCLIENT.equals(getLibrary())) {
additionalProperties.put("jackson", "true");
} else if (VERTX.equals(getLibrary())) {
typeMapping.put("file", "AsyncFile");
importMapping.put("AsyncFile", "io.vertx.core.file.AsyncFile");
Expand Down
Loading

0 comments on commit b90c53d

Please sign in to comment.