Skip to content

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

@msrd0

Description

@msrd0
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions