Skip to content

[Kotlin][Client] Added Kotlinx Serialization for JVM/Retrofit2/OkHttp3&4 #6916

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

Merged
merged 76 commits into from
Mar 19, 2021

Conversation

kuFEAR
Copy link
Contributor

@kuFEAR kuFEAR commented Jul 12, 2020

Added supporting for Kotlinx.serialization 1.1.0 on JVM with base set of JVM type serialize adapters, also update Kotlin 1.4.30 and Gradle wrapper 6.8.3

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. 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/config/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@jimschubert (2017/09) ❤️, @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03)

@wing328
Copy link
Member

wing328 commented Aug 8, 2020

@kuFEAR thanks for the PR. Can you please resolve the merge conflicts when you've time?

@wing328 wing328 added this to the 5.0.0 milestone Aug 10, 2020
@wing328
Copy link
Member

wing328 commented Aug 10, 2020

Shippable CI failed with the following errors:

===> Downloaded package, caching at /root/.cache/rebar3/hex/hexpm/packages/rebar3_proper-0.12.0.tar
===> Compiling rebar3_proper
===> Verifying dependencies...
===> Fetching jsx v2.9.0
===> Downloaded package, caching at /root/.cache/rebar3/hex/hexpm/packages/jsx-2.9.0.tar
===> Fetching proper v1.3.0
===> Downloaded package, caching at /root/.cache/rebar3/hex/hexpm/packages/proper-1.3.0.tar
===> Compiling proper
===> Compiling jsx
===> Compiling petstore
Downloading https://services.gradle.org/distributions/gradle-6.0-bin.zip
.........10%.........20%.........30%.........40%.........50%.........60%.........70%.........80%.........90%.........100%

Welcome to Gradle 6.0!

Here are the highlights of this release:
 - Substantial improvements in dependency management, including
   - Publishing Gradle Module Metadata in addition to pom.xml
   - Advanced control of transitive versions
   - Support for optional features and dependencies
   - Rules to tweak published metadata
 - Support for Java 13
 - Faster incremental Java and Groovy compilation
 - New Zinc compiler for Scala
 - VS2019 support
 - Support for Gradle Enterprise plugin 3.0

For more details see https://docs.gradle.org/6.0/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :
Kotlin Multiplatform Projects are an experimental feature.

Please wait while Kotlin/Native compiler 1.3.72 is being installed.
Download https://download.jetbrains.com/kotlin/native/builds/releases/1.3.72/linux/kotlin-native-linux-1.3.72.tar.gz (102.85 MB)
Download https://download.jetbrains.com/kotlin/native/builds/releases/1.3.72/linux/kotlin-native-linux-1.3.72.tar.gz finished, took 2 s 784 ms
Unpack Kotlin/Native compiler to /root/.konan/kotlin-native-linux-1.3.72
Unpack Kotlin/Native compiler to /root/.konan/kotlin-native-linux-1.3.72 finished, took 3 s 178 ms

FAILURE: Build failed with an exception.

* Where:
Build file '/root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/build.gradle' line: 31

* What went wrong:
A problem occurred evaluating root project 'kotlin-client-petstore-multiplatform'.
> Operation is not supported for read-only collection

* 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 29s

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0/userguide/command_line_interface.html#sec:command_line_warnings
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (bundle-test) on project KotlinMultiPlatformClientTests: Command execution failed.: Process exited with an error: 1 (Exit value: 1) -> [Help 1]

Looks like the cause is /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/build.gradle line: 31 ? Any idea why it fails?

@kuFEAR
Copy link
Contributor Author

kuFEAR commented Aug 10, 2020

Oh, I'll fix multiplatform SafeEnum build today

@wing328
Copy link
Member

wing328 commented Aug 10, 2020

Now Shippable CI reports the following errors:

> Task :compileKotlinIosArm64 SKIPPED
> Task :compileKotlinIosX64 SKIPPED

> Task :compileKotlinJs FAILED
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt: (144, 79): Using 'list: KSerializer<List<T>>' is an error. Deprecated in the favour of the same extension from builtins package
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt: (145, 60): Using 'withName(String): SerialDescriptor' is an error. Deprecated in the favour of PrimitiveDescriptor factory function
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt: (188, 79): Using 'list: KSerializer<List<T>>' is an error. Deprecated in the favour of the same extension from builtins package
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt: (189, 60): Using 'withName(String): SerialDescriptor' is an error. Deprecated in the favour of PrimitiveDescriptor factory function
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt: (107, 98): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public fun <T : Any> KClass<???>.serializer(): KSerializer<???> defined in kotlinx.serialization
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt: (107, 125): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public fun <T : Any> KClass<???>.serializer(): KSerializer<???> defined in kotlinx.serialization
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt: (108, 60): Using 'withName(String): SerialDescriptor' is an error. Deprecated in the favour of PrimitiveDescriptor factory function
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt: (106, 81): Using 'list: KSerializer<List<T>>' is an error. Deprecated in the favour of the same extension from builtins package
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt: (107, 60): Using 'withName(String): SerialDescriptor' is an error. Deprecated in the favour of PrimitiveDescriptor factory function
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt: (147, 81): Using 'list: KSerializer<List<T>>' is an error. Deprecated in the favour of the same extension from builtins package
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt: (148, 60): Using 'withName(String): SerialDescriptor' is an error. Deprecated in the favour of PrimitiveDescriptor factory function
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt: (10, 52): Using 'withName(String): SerialDescriptor' is an error. Deprecated in the favour of PrimitiveDescriptor factory function
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt: (10, 52): Using 'withName(String): SerialDescriptor' is an error. Deprecated in the favour of PrimitiveDescriptor factory function
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ApiResponse.kt: (18, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ApiResponse.kt: (19, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ApiResponse.kt: (20, 47): Unresolved reference: SafeEnumAdapter
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Category.kt: (18, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Category.kt: (19, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Category.kt: (20, 47): Unresolved reference: SafeEnumAdapter
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt: (18, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt: (19, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt: (20, 47): Unresolved reference: SafeEnumAdapter
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt: (46, 26): Type mismatch: inferred type is KClass<Order.Status.Serializer> but KClass<out KSerializer<*>> was expected
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt: (47, 23): 'serialName' overrides nothing
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt: (47, 65): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt: (52, 29): Unresolved reference: SafeEnumAdapter
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (20, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (21, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (22, 47): Unresolved reference: SafeEnumAdapter
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (35, 34): Unresolved reference: Required
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (36, 39): Unresolved reference: Required
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (48, 26): Type mismatch: inferred type is KClass<Pet.Status.Serializer> but KClass<out KSerializer<*>> was expected
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (49, 23): 'serialName' overrides nothing
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (49, 65): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt: (54, 29): Unresolved reference: SafeEnumAdapter
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Tag.kt: (18, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Tag.kt: (19, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Tag.kt: (20, 47): Unresolved reference: SafeEnumAdapter
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/User.kt: (18, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/User.kt: (19, 47): Unresolved reference: SafeEnum
e: /root/src/github.com/OpenAPITools/openapi-generator/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/User.kt: (20, 47): Unresolved reference: SafeEnumAdapter

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlinJs'.
> Compilation error. See log for more details

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 46s
1 actionable task: 1 executed
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (bundle-test) on project KotlinMultiPlatformClientTests: Command execution failed.: Process exited with an error: 1 (Exit value: 1) -> [Help 1]

When you've time, please take another look. If you need help from us, let us know.

@kuFEAR
Copy link
Contributor Author

kuFEAR commented Aug 11, 2020

@wing328 I'll wait kotlin update from this PR https://github.com/OpenAPITools/openapi-generator/pull/7149/files, now we have some overlaps in changes and double work

@kuFEAR
Copy link
Contributor Author

kuFEAR commented Aug 11, 2020

@wing328 Also I want to add exact SerializeAdapter instead @ContextualSerializer for each custom properties, how I can extend CodegenProperty for that, and is it acceptable changes for generators in common? Now I can use only isPrimitiveType/isEnum/complexType and some times it works incorrect
the second moment, that we add import section with types which not present in generated models and then they highlighted as unused

@kuFEAR kuFEAR changed the title [Kotlin][Client] Added Kotlin.Serialization for JVM/Retrofit2 [Kotlin][Client] Added Kotlinx Serialization for JVM/Retrofit2 Oct 18, 2020
@kuFEAR kuFEAR force-pushed the kotlin_serialization_jvm branch from d06ea1d to 15f3f59 Compare October 18, 2020 19:13
@kuFEAR
Copy link
Contributor Author

kuFEAR commented Nov 20, 2020

@wing328 @jimschubert Hi, can you re-run circleci build? as I notice it failed on downloading fastxml.jackson

@wing328 wing328 modified the milestones: 5.0.0, 5.0.1 Dec 21, 2020
@wing328 wing328 modified the milestones: 5.0.1, 5.1.0 Feb 8, 2021
…zation_jvm

# Conflicts:
#	modules/openapi-generator/src/main/resources/kotlin-client/build.gradle.mustache
#	pom.xml
#	samples/client/petstore/kotlin-gson/build.gradle
#	samples/client/petstore/kotlin-gson/pom.xml
#	samples/client/petstore/kotlin-jackson/build.gradle
#	samples/client/petstore/kotlin-jackson/pom.xml
#	samples/client/petstore/kotlin-json-request-string/build.gradle
#	samples/client/petstore/kotlin-json-request-string/pom.xml
#	samples/client/petstore/kotlin-jvm-okhttp4-coroutines/build.gradle
#	samples/client/petstore/kotlin-jvm-okhttp4-coroutines/pom.xml
#	samples/client/petstore/kotlin-moshi-codegen/build.gradle
#	samples/client/petstore/kotlin-moshi-codegen/pom.xml
#	samples/client/petstore/kotlin-nonpublic/build.gradle
#	samples/client/petstore/kotlin-nonpublic/pom.xml
#	samples/client/petstore/kotlin-nullable/build.gradle
#	samples/client/petstore/kotlin-nullable/pom.xml
#	samples/client/petstore/kotlin-okhttp3/build.gradle
#	samples/client/petstore/kotlin-okhttp3/pom.xml
#	samples/client/petstore/kotlin-retrofit2-rx3/build.gradle
#	samples/client/petstore/kotlin-retrofit2-rx3/pom.xml
#	samples/client/petstore/kotlin-retrofit2/build.gradle
#	samples/client/petstore/kotlin-retrofit2/pom.xml
#	samples/client/petstore/kotlin-string/build.gradle
#	samples/client/petstore/kotlin-string/pom.xml
#	samples/client/petstore/kotlin-threetenbp/build.gradle
#	samples/client/petstore/kotlin-threetenbp/pom.xml
#	samples/client/petstore/kotlin-uppercase-enum/build.gradle
#	samples/client/petstore/kotlin/build.gradle
#	samples/client/petstore/kotlin/gradle/wrapper/gradle-wrapper.jar
#	samples/client/petstore/kotlin/gradlew
#	samples/client/petstore/kotlin/pom.xml
delete petstore/kotlin unit tests
@kuFEAR
Copy link
Contributor Author

kuFEAR commented Mar 12, 2021

@wing328 Hi! I have PR for some time in repo. Can you approve it? I think it will be really useful for many projects

@wing328
Copy link
Member

wing328 commented Mar 13, 2021

@kuFEAR thanks again for the PR. Let me try to review shortly....

@wing328
Copy link
Member

wing328 commented Mar 13, 2021

@kuFEAR quickly went through it. looks good overall 👍

Have minor 2 questions. Free in the coming week to discuss it further? PM via Slack to discuss further. Have a nice weekend.

@wing328
Copy link
Member

wing328 commented Mar 17, 2021

As discussed, please recover the following deleted test files:

samples/client/petstore/kotlin-string/src/test/kotlin/org/openapitools/client/PetApiTest.kt
samples/client/petstore/kotlin-threetenbp/src/test/kotlin/org/openapitools/client/PetApiTest.kt
samples/client/petstore/kotlin/src/test/kotlin/org/openapitools/client/PetApiTest.kt
samples/client/petstore/kotlin/src/test/kotlin/org/openapitools/client/StoreApiTest.kt

@kuFEAR kuFEAR force-pushed the kotlin_serialization_jvm branch from 78b269a to 54bcbc1 Compare March 17, 2021 17:31
remove adding pom.xml to kotlin client samples
@kuFEAR kuFEAR force-pushed the kotlin_serialization_jvm branch from 54bcbc1 to 7c3f170 Compare March 17, 2021 17:57
@kuFEAR kuFEAR changed the title [Kotlin][Client] Added Kotlinx Serialization for JVM/Retrofit2 [Kotlin][Client] Added Kotlinx Serialization for JVM/Retrofit2/OkHttp3&4 Mar 17, 2021
@wing328
Copy link
Member

wing328 commented Mar 19, 2021

All tests passed. I may file a PR later to make minor enhancements.

Thanks again for the PR.

@wing328 wing328 merged commit d657e95 into OpenAPITools:master Mar 19, 2021
@wing328
Copy link
Member

wing328 commented Mar 22, 2021

@kuFEAR thanks for the PR, which has been included in the v5.1.0 release: https://twitter.com/oas_generator/status/1373636654024380423

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.

4 participants