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

[Java] Add support for Spring 5 WebClient #435

Merged
merged 8 commits into from
Jul 4, 2018
Merged

[Java] Add support for Spring 5 WebClient #435

merged 8 commits into from
Jul 4, 2018

Conversation

0v1se
Copy link
Contributor

@0v1se 0v1se commented Jul 2, 2018

PR checklist

  • [-] Read the contribution guidelines.
  • [-] Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • [-] Filed the PR against the correct branch: master, 3.1.x, 4.0.x. Default: master.
  • [-] Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Basic support for Spring 5 WebClient with project reactor's Mono/Flux

@jmini
Copy link
Member

jmini commented Jul 2, 2018

Shippable — Run 1154 status is FAILED.

The new sample output samples/client/petstore/java/webclient is not up-to-date with the generator.

Please run:

  • mvn clean verify on the root
  • run bin/java-petstore-webclient.sh
  • commit the changes to this PR

@jmini jmini changed the title Add support for Spring 5 WebClient [Java] Add support for Spring 5 WebClient Jul 2, 2018
@jmini
Copy link
Member

jmini commented Jul 2, 2018

If you like you can credit yourself in the root README.md under template creator:
https://github.com/OpenAPITools/openapi-generator#template-creator

@jmini
Copy link
Member

jmini commented Jul 2, 2018

For the CI, can you please add the new generated sample to /CI/pom.xml.circleci:

 <module>samples/client/petstore/java/webclient</module> 

Here:

<module>samples/client/petstore/java/feign</module>
<module>samples/client/petstore/java/jersey1</module>
<module>samples/client/petstore/java/jersey2</module>
<module>samples/client/petstore/java/okhttp-gson</module>
<module>samples/client/petstore/java/retrofit</module>
<module>samples/client/petstore/java/retrofit2</module>
<module>samples/client/petstore/java/retrofit2rx</module>
<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/vertx</module>
<module>samples/client/petstore/java/resteasy</module>
<module>samples/client/petstore/java/google-api-client</module>
<module>samples/client/petstore/java/rest-assured</module>

(the list is not really sorted... You can add your project somewhere near the other java client tests)

@jmini
Copy link
Member

jmini commented Jul 3, 2018

Thank you for the update.


I have fetch your branch on my computer to perform some tests

I have tried to run:

mvn verify -f samples/client/petstore/java/webclient

An I got a lot of compile errors, about org.threeten.bp missing. Maybe you should generate the sample with java8 date lib.

I also have compile error like this one:

[ERROR] /Users/jbr/Git/openapi-generator/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/api/PetApi.java:[144,72] cannot find symbol
[ERROR]   symbol:   variable CollectionFormat
[ERROR]   location: class org.openapitools.client.ApiClient

@0v1se
Copy link
Contributor Author

0v1se commented Jul 3, 2018

@jmini thanks
will check this and update

@0v1se
Copy link
Contributor Author

0v1se commented Jul 3, 2018

@jmini fixed some bugs.
Sample project compiles ok now.

I disabled threetenbp this way (no need for threetenbp cause java8 is required):

        if (WEBCLIENT.equals(getLibrary()) && "threetenbp".equals(dateLibrary)) {
            dateLibrary = "java8";
        }

Is it ok to disable threeten this way? Or is there better method?

@jmini
Copy link
Member

jmini commented Jul 3, 2018

Is it ok to disable threeten this way? Or is there better method?

Good question. For the moment we do not have really a way to define that some options are only available with certain lib or other config.

I had a quick look at the code, vertx requires java8 by doing it setJava8Mode(true) and additionalProperties.put("java8", "true") in the big if-elseif block. Maybe you can do it in a similar manner:

} else if (VERTX.equals(getLibrary())) {
typeMapping.put("file", "AsyncFile");
importMapping.put("AsyncFile", "io.vertx.core.file.AsyncFile");
setJava8Mode(true);
additionalProperties.put("java8", "true");

Copy link
Member

@jmini jmini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me in general.

Because you have raised it I have started to think about where to do the fixes for unsupported/wrong config.

I did not check this in detail.

@@ -151,6 +153,10 @@ public String getHelp() {

@Override
public void processOpts() {
if (WEBCLIENT.equals(getLibrary()) && "threetenbp".equals(dateLibrary)) {
Copy link
Member

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.

@@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I would set other values like java8Mode, dateLibrary...

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:

  • gets params and sets fiels (e.g dateLibrary)
  • does some actions according to fields
    For example, in the end of processOpts:
        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)
and the method for checking/updating fields should be added.

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?

Copy link
Member

Choose a reason for hiding this comment

The 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 processOpts()) in a separated PR.

@jmini
Copy link
Member

jmini commented Jul 4, 2018

I have tested the sample locally:

$ mvn verify -f samples/client/petstore/java/webclient/
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building petstore-webclient 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.694 s
[INFO] Finished at: 2018-07-03T16:01:27+02:00
[INFO] Final Memory: 21M/256M
[INFO] ------------------------------------------------------------------------

Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good 👍 we can update the README later to specify JDK8 as the minimal version.

@jmini jmini added this to the 3.1.0 milestone Jul 4, 2018
@jmini jmini merged commit b90c53d into OpenAPITools:master Jul 4, 2018
@jmini
Copy link
Member

jmini commented Jul 4, 2018

@0v1se: Thank you a lot for this contribution.

@jmini
Copy link
Member

jmini commented Jul 4, 2018

Twitt: https://twitter.com/oas_generator/status/1014415775766073344

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants