-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[Java] Add support for Spring 5 WebClient #435
Changes from all commits
b4a6143
4d87ba0
8cf7adb
a25cf38
d6f6f66
1af504d
355b515
315b312
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"library": "webclient", | ||
"artifactId": "petstore-webclient" | ||
} |
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 |
---|---|---|
|
@@ -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"; | ||
|
@@ -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"); | ||
|
@@ -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)) { | ||
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here I would set other values like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first I added this check at line 290, but it was not working, because dateLibrary is used in AbstractJavaCodegen.processOpts(), so setting it on line 290 doesn't work. As you stated, setting it on line 156 doesn't always work either (because it's set inside AbstractJavaCodegen.processOpts if parameter about date library is present). I think, the only solution is to divide processOpts(). Currently it does some things:
if ("threetenbp".equals(dateLibrary)) {
additionalProperties.put("threetenbp", "true");
additionalProperties.put("jsr310", "true");
typeMapping.put("date", "LocalDate");
typeMapping.put("DateTime", "OffsetDateTime");
importMapping.put("LocalDate", "org.threeten.bp.LocalDate");
importMapping.put("OffsetDateTime", "org.threeten.bp.OffsetDateTime");
} else if ("joda".equals(dateLibrary)) { Possibly, this method (processOpts) should do only one thing (should be divided) Actually, it's not a big deal now. I can add back threetenbp support (but it's useless cause java8 support only), then there is no reason to do all these things now. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you a lot for the analysis and the explanations. I think that we can do the refactoring you have proposed (splitting |
||
} else if (VERTX.equals(getLibrary())) { | ||
typeMapping.put("file", "AsyncFile"); | ||
importMapping.put("AsyncFile", "io.vertx.core.file.AsyncFile"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that this check is too early. I am not sure, but I think that if the value is set to something on the command line, the value will be set with
super.processOpts()
and will override your check.If possible I would override the wrong/unsupported values in the "else if" block line 290.