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

[kotlin-client] Add support okhttp3 and Android 4.x #4008

Merged

Conversation

4brunu
Copy link
Contributor

@4brunu 4brunu commented Oct 1, 2019

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, ./bin/openapi3/{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\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.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

@jimschubert (2017/09) ❤️, @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04)

This PR adds support for Add support okhttp3 and Android 4.x and fixes #4007

@wing328
Copy link
Member

wing328 commented Oct 1, 2019

@4brunu thanks for the PR. What about naming the option as "library" instead to make it more consistent with other generators (e.g. Java, Ruby) when it comes to supporting more than 1 HTTP library?

@4brunu
Copy link
Contributor Author

4brunu commented Oct 1, 2019

@wing328 it's done, I also rerun the tests and the pet projects 🙂

@4brunu
Copy link
Contributor Author

4brunu commented Oct 1, 2019

Hi, I was trying to do the changes but now the generator with the pet projects it's not working.
I tried to look at the code but I can't find what's wrong.
Maybe renaming jvm to jvm-okhttp3 and jvm-okhttp4?

Here is the commit and the logs.
It looks like it can't find a file.
Can you please take a look at it?
Because I don't know what's wrong :S

Log # START SCRIPT: bin/kotlin-client-okhttp3.sh [main] INFO o.o.codegen.DefaultGenerator - OpenAPI Generator: kotlin (client) [main] INFO o.o.codegen.DefaultGenerator - Generator 'kotlin' is considered stable. [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] INFO o.o.c.l.AbstractKotlinCodegen - Environment variable KOTLIN_POST_PROCESS_FILE not defined so the Kotlin code may not be properly formatted. To define it, try 'export KOTLIN_POST_PROCESS_FILE="/usr/local/bin/ktlint -F"' (Linux/Mac) [main] INFO o.o.c.l.AbstractKotlinCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI). [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/ApiResponse.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/ApiResponse.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/Category.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/Category.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/Order.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/Order.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/Pet.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/Pet.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/Tag.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/Tag.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/models/User.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/User.md [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.DefaultCodegen - Multiple MediaTypes found, using only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.DefaultCodegen - Multiple MediaTypes found, using only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] WARN o.o.codegen.utils.ModelUtils - Multiple schemas found in content, returning only the first one [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/PetApi.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/StoreApi.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/docs/UserApi.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/README.md [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/build.gradle [main] INFO o.o.codegen.AbstractGenerator - writing file /Users/bruno.coelho/Developer/openapi-generator/samples/client/petstore/kotlin-okhttp3/settings.gradle [main] ERROR o.o.codegen.AbstractGenerator - kotlin-client/infrastructure/ApiClient.kt.mustache (No such file or directory) [main] ERROR o.o.codegen.AbstractGenerator - kotlin-client/infrastructure/ApiClient.kt.mustache (No such file or directory) [main] ERROR o.o.codegen.AbstractGenerator - can't load template kotlin-client/infrastructure/ApiClient.kt.mustache [main] ERROR o.o.codegen.AbstractGenerator - can't load template kotlin-client/infrastructure/ApiClient.kt.mustache Exception in thread "main" java.lang.RuntimeException: Could not generate supporting file 'SupportingFile: templateFile: infrastructure/ApiClient.kt.mustache folder: src/main/kotlin/org/openapitools/client/infrastructure destinationFilename: ApiClient.kt ' at org.openapitools.codegen.DefaultGenerator.generateSupportingFiles(DefaultGenerator.java:751) at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:930) at org.openapitools.codegen.cmd.Generate.run(Generate.java:408) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60) Caused by: java.lang.RuntimeException: can't load template kotlin-client/infrastructure/ApiClient.kt.mustache at org.openapitools.codegen.AbstractGenerator.readTemplate(AbstractGenerator.java:122) at org.openapitools.codegen.DefaultGenerator.getFullTemplateContents(DefaultGenerator.java:941) at org.openapitools.codegen.templating.MustacheEngineAdapter.compileTemplate(MustacheEngineAdapter.java:51) at org.openapitools.codegen.DefaultGenerator.generateSupportingFiles(DefaultGenerator.java:723) ... 3 more cp: CI/samples.ci/client/petstore/kotlin-okhttp3/pom.xml: No such file or directory

Can you please check the commit to see if this is was you had in mind?

Since kotlin has the concept of jvm and multiplatform library, I'm not sure if it works nice to have a jvm-okhttp4 and jvm-okhttp3.
What do you think?

@wing328
Copy link
Member

wing328 commented Oct 2, 2019

Maybe renaming jvm to jvm-okhttp3 and jvm-okhttp4?

Sounds good to me

@wing328
Copy link
Member

wing328 commented Oct 2, 2019

Can you please check the commit to see if this is was you had in mind?

I'll try to find some time to review later today.

@wing328
Copy link
Member

wing328 commented Oct 2, 2019

Can you please push 4brunu@7190a80 to this branch/PR when you've time? Easy for me to try to it and figure out what's wrong.

…-support-okhttp3

# Conflicts:
#	modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache
@4brunu
Copy link
Contributor Author

4brunu commented Oct 2, 2019

@wing328 done. thanks for helping 👍

@wing328
Copy link
Member

wing328 commented Oct 2, 2019

@4brunu I've figured out the reason and got a "workaround' to make it work with all 3 different library settings. Please PM tomorrow (Thur) via Slack when you've time.

Slack channel: https://join.slack.com/t/openapi-generator/shared_invite/enQtNzAyNDMyOTU0OTE1LTY5ZDBiNDI5NzI5ZjQ1Y2E5OWVjMjZkYzY1ZGM2MWQ4YWFjMzcyNDY5MGI4NjQxNDBiMTlmZTc5NjY2ZTQ5MGM

@4brunu
Copy link
Contributor Author

4brunu commented Oct 3, 2019

Thanks for the help, now it's working 🙂
The CI is failing, but I took a look at the logs and I think this is not related to the changes in this PR.
Please let me know if there any more changes required to merge this PR.
Thanks 👍

@4brunu
Copy link
Contributor Author

4brunu commented Oct 3, 2019

Don't merge this branch! After doing some more tests, It's not working.

@4brunu
Copy link
Contributor Author

4brunu commented Oct 3, 2019

@wing328 the Serialisation and Parcelable/Parcelize features stop working.

When migrating to library it stoped working...
Here was working 7190a80 and after that it's nor working.

Here is a screenshot that shows what's wrong in the models.
Screenshot 2019-10-03 at 14 36 15

The generator is not generating the imports and @Json(name = "...")

Do you have any idea why?

@4brunu
Copy link
Contributor Author

4brunu commented Oct 3, 2019

@wing328 sorry for the spam...
I updated the test case to have the correct output.
This way is very simple to test issue.
You checkout this branch, run the following command sh bin/kotlin-client-all.sh and in your git, you shouldn't see any change.
If you see any change (you will) that's the issue that shouldn't happen.
Thanks 🙂

@wing328 wing328 modified the milestones: 4.1.3, 4.2.0 Oct 4, 2019
@4brunu
Copy link
Contributor Author

4brunu commented Oct 4, 2019

@wing328 Sorry for all of this, but it's now fixed.
I removed a flag jvm -> true that was still necessary that I thought that wasn't, and that tah was used in some places.
But now with the last commit 5b9dc22 everything is working again.
For me this can now be merged.

@wing328
Copy link
Member

wing328 commented Oct 9, 2019

CI failure not related to this PR.

@wing328 wing328 merged commit 7a369d3 into OpenAPITools:master Oct 9, 2019
@4brunu 4brunu deleted the feature/kotlin-client-support-okhttp3 branch October 10, 2019 14:01
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.

[REQ] [kotlin-client] Add support for OkHttp3 to support Android API 4.X
2 participants