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: Fix kotlinx_serialization #9576

Merged
merged 1 commit into from
May 31, 2021

Conversation

saschpe
Copy link
Contributor

@saschpe saschpe commented May 25, 2021

And update to Kotlin 1.5.0 and kotlinx.serialization 1.2.1. Fix nested
enum annotation '@serializable' instead of '@KSerializable' when
'kotlinx_serialization' is used. Fix missing JsonMediaType in
ApiClient.kt (#9242). Add 'kotlinx_serialization' serialization library
to documentation.

Resolves #9242

@jimschubert @rsinukov @wing328 @dr4ke616 @karismann @Zomzog @andrewemery @4brunu @yutaka0m

Tested with serializationLibrary set to gson, kotlinx_serialization and default (moshi) as well as library set to multiplatform and default (jvm-okhttp4).

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@saschpe saschpe changed the title Kotlin client gson Kotlin-Client: Fix kotlinx_serialization May 25, 2021
val method: RequestMethod,
val path: String,
val headers: MutableMap<String, String> = mutableMapOf(),
val query: MutableMap<String, List<String>> = mutableMapOf(),
val body: kotlin.Any? = null
val body: T? = null
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this change has other hidden implications...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Others than providing stronger (or previously missing) type information, I don't think so. I generated code for several combinations of library and serializationLibrary but didn't run all of them. However, previously not a single combination worked reliably.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be clearer, I like this change, I think it makes sense, I was just thinking if this could have some side effects that I didn't think of.

@4brunu
Copy link
Contributor

4brunu commented May 25, 2021

Could you please remove the changes from #9358 on this PR?
Because that makes it harder to review and merge it.

@4brunu
Copy link
Contributor

4brunu commented May 26, 2021

Can you please run to try to fix CI?

./mvnw clean package 
./bin/generate-samples.sh

Thanks

@saschpe
Copy link
Contributor Author

saschpe commented May 26, 2021

Can you please run to try to fix CI?

./mvnw clean package 
./bin/generate-samples.sh

Thanks

Done. Sorry, I forgot about it after the import change. My bad.

@4brunu
Copy link
Contributor

4brunu commented May 26, 2021

@saschpe could you please fix the merge conflicts with the master branch please?

@saschpe
Copy link
Contributor Author

saschpe commented May 26, 2021

@saschpe could you please fix the merge conflicts with the master branch please?

Done. Not sure about the recent Travis-CI error though

@wing328
Copy link
Member

wing328 commented May 28, 2021

@saschpe thanks for the PR. When I ran gradle wrapper && ./gradlew build -x test in samples/client/petstore/kotlin, I got the following errors:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/williamcheng/Code/openapi-generator/samples/client/petstore/kotlin/build.gradle' line: 31

* What went wrong:
A problem occurred evaluating root project 'kotlin-petstore-client'.
> Could not find method compile() for arguments [org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

While the same command runs fine in the master. I wonder if you can take another look to see if you can reproduce the issue.

@saschpe
Copy link
Contributor Author

saschpe commented May 28, 2021

@wing328 Sure, I'll take another look soon.

And update to Kotlin 1.5.0 and kotlinx.serialization 1.2.1. Fix nested
enum annotation '@serializable' instead of '@KSerializable' when
'kotlinx_serialization' is used. Fix missing JsonMediaType in
ApiClient.kt (OpenAPITools#9242). Add 'kotlinx_serialization' serialization library
to documentation. Use explicity type in RequestConfig to keep type
information for JSON serialization.

Resolves OpenAPITools#9242
@saschpe
Copy link
Contributor Author

saschpe commented May 31, 2021

@wing328 Sure, I'll take another look soon.

Should be fixed now

@4brunu
Copy link
Contributor

4brunu commented May 31, 2021

CI failures now are not related to this PR.

@wing328
Copy link
Member

wing328 commented May 31, 2021

No luck. Still got the same error:

$ gradle wrapper

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/williamcheng/Code/openapi-generator2/samples/client/petstore/kotlin/build.gradle' line: 31

* What went wrong:
A problem occurred evaluating root project 'kotlin-petstore-client'.
> Could not find method compile() for arguments [org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

Does it work for you locally?

@4brunu
Copy link
Contributor

4brunu commented May 31, 2021

Maybe the gradle version also needs to be updated?

@wing328
Copy link
Member

wing328 commented May 31, 2021

I'm using 7.0.2:

$ gradle -version

------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------

Build time:   2021-05-14 12:02:31 UTC
Revision:     1ef1b260d39daacbf9357f9d8594a8a743e2152e

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          15.0.2 (Oracle Corporation 15.0.2+7)
OS:           Mac OS X 11.2.3 x86_64

Can you also test it locally to see if it works for you?

git checkout -b saschpe-kotlin-client-gson master
git pull https://github.com/saschpe/openapi-generator.git kotlin-client-gson

@4brunu
Copy link
Contributor

4brunu commented May 31, 2021

I tried in my machine using gradle wrapper and it works.

./gradlew build -x test

So it may be an issue with gradle version 7.X, but I think it's recommended to use the gradle wrapper.

@saschpe
Copy link
Contributor Author

saschpe commented May 31, 2021

Yes, gradle wrapper uses whatever Gradle version the system provides. The Gradle wrapper is almost always the better choice.

@4brunu
Copy link
Contributor

4brunu commented May 31, 2021

I can fix the compatibility with gradle 7.X in a different PR.
It's basically replacing compile´ with implementation, testCompilewithtestImplementation` and so on.
But this is an old issue.

@wing328
Copy link
Member

wing328 commented May 31, 2021

If you look at the error message above. I simply ran gradle wrapper to start with and got the error message right away. Am I using gradle correctly by running gradle wrapper to being with?

@4brunu
Copy link
Contributor

4brunu commented May 31, 2021

Try to use the following command ./gradlew build -x test

@4brunu
Copy link
Contributor

4brunu commented May 31, 2021

The problem is that you are using gradle 7.X to try to download the gradle wrapper, but the gradle 7.X looks at the build.gradle file and see the use of removed API's and show that error message.
I will create a PR to fix this, shortly after this PR is merged.

@wing328
Copy link
Member

wing328 commented May 31, 2021

👌

@wing328 wing328 merged commit 173a349 into OpenAPITools:master May 31, 2021
@4brunu
Copy link
Contributor

4brunu commented May 31, 2021

To add more onto this, the gradle wrapper is always copied together with the generated code, so there is no need to download it, you can just use it straight away.

@wing328
Copy link
Member

wing328 commented May 31, 2021

Previously there was an issue caught by the CI that we need to run gradle wrapper before running ./gradlew build -x test.

@4brunu
Copy link
Contributor

4brunu commented May 31, 2021

Oh, I see, thanks for letting us know 👍

@saschpe saschpe deleted the kotlin-client-gson branch January 23, 2023 11:39
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.

[BUG][KOTLIN CLIENT] Generator generates invalid code when using kotlinx.serialization
3 participants