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

[BUG][KOTLIN CLIENT] Generator generates invalid code when using kotlinx.serialization #9242

Closed
msrd0 opened this issue Apr 12, 2021 · 0 comments · Fixed by #9576
Closed

Comments

@msrd0
Copy link

msrd0 commented Apr 12, 2021

Description

Generator generates invalid code when using kotlinx.serialization

openapi-generator version

5.1.0 installed from the official ArchLinux package repository

OpenAPI declaration file content or url

https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml

Generation Details

openapi-generator generate -g kotlin -i petstore.yaml -p serializationLibrary=kotlinx_serialization

Steps to reproduce
  • Run above command to generate the source code
  • Run gradle build
  • Observe the following error message
e: /tmp/oas/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt: (118, 29): Expecting an element
e: /tmp/oas/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt: (101, 82): Type mismatch: inferred type is T but DeserializationStrategy<TypeVariable(T)> was expected
e: /tmp/oas/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt: (101, 89): No value passed for parameter 'string'
e: /tmp/oas/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt: (101, 91): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public final fun ByteArray.toRequestBody(contentType: MediaType? = ..., offset: Int = ..., byteCount: Int = ...): RequestBody defined in okhttp3.RequestBody.Companion
public final fun String.toRequestBody(contentType: MediaType? = ...): RequestBody defined in okhttp3.RequestBody.Companion
public final fun ByteString.toRequestBody(contentType: MediaType? = ...): RequestBody defined in okhttp3.RequestBody.Companion
e: /tmp/oas/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt: (249, 50): Type mismatch: inferred type is T but SerializationStrategy<TypeVariable(T)> was expected
e: /tmp/oas/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt: (249, 55): No value passed for parameter 'value'
Suggest a fix

This line is probably missing support for kotlinx.serialization: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache#L175

saschpe added a commit to saschpe/openapi-generator that referenced this issue May 31, 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 (OpenAPITools#9242). Add 'kotlinx_serialization' serialization library
to documentation. Use explicity type in RequestConfig to keep type
information for JSON serialization.

Resolves OpenAPITools#9242
wing328 pushed a commit that referenced this issue May 31, 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. Use explicity type in RequestConfig to keep type
information for JSON serialization.

Resolves #9242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant