-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
When using an OpenAPI schema that describes a file upload supporting multiple files, the generated kotlin code fails to compile.
This started after the 7.0.0 release (the kotlin code compiles successfully in 6.6.0, but I suspect it only supports a single file).
openapi-generator version
7.4.0 (issue introduced in 7.0.0)
OpenAPI declaration file content or url
testcase.yaml:
openapi: 3.0.0
info:
version: "1.0.0"
title: TestAPI
servers:
- url: https://api.example.com/
description: API endpoint
paths:
/file-upload:
post:
operationId: uploadFile
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
# The property name 'file' will be used for all files.
file:
type: array
items:
type: string
format: binary
responses:
'204':
description: File uploadedtestconfig.json:
{
"artifactId": "example-client",
"artifactVersion": "1.0.0",
"groupId": "com.example",
"packageName": "com.example.kotlin.api",
"enumPropertyNaming": "UPPERCASE",
"library": "multiplatform",
"dateLibrary": "string",
"omitGradlePluginVersions": false
}Generation Details
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v7.4.0 generate \
-i /local/testcase.yaml \
-g kotlin \
-c /local/testconfig.json \
-o /local/generated
Steps to reproduce
- Create the testcase.yaml and testconfig.json as described in this issue.
- Run the code generation, then run
./gradlw clean assembleto try to build the kotlin client.
The following error is reported:
> Task :compileCommonMainKotlinMetadata FAILED
e: file:///***/generated_test/src/commonMain/kotlin/com/example/kotlin/api/apis/DefaultApi.kt:56:23 Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun <T, C : Iterable<TypeVariable(T)>> TypeVariable(C).onEach(action: (TypeVariable(T)) -> Unit): TypeVariable(C) defined in kotlin.collections
public inline fun <K, V, M : Map<out TypeVariable(K), TypeVariable(V)>> TypeVariable(M).onEach(action: (Map.Entry<TypeVariable(K), TypeVariable(V)>) -> Unit): TypeVariable(M) defined in kotlin.collections
public inline fun <S : CharSequence> TypeVariable(S).onEach(action: (Char) -> Unit): TypeVariable(S) defined in kotlin.text
public inline fun <T> Array<out TypeVariable(T)>.onEach(action: (TypeVariable(T)) -> Unit): Array<out TypeVariable(T)> defined in kotlin.collections
public inline fun BooleanArray.onEach(action: (Boolean) -> Unit): BooleanArray defined in kotlin.collections
public inline fun ByteArray.onEach(action: (Byte) -> Unit): ByteArray defined in kotlin.collections
public inline fun CharArray.onEach(action: (Char) -> Unit): CharArray defined in kotlin.collections
public inline fun DoubleArray.onEach(action: (Double) -> Unit): DoubleArray defined in kotlin.collections
public inline fun FloatArray.onEach(action: (Float) -> Unit): FloatArray defined in kotlin.collections
public inline fun IntArray.onEach(action: (Int) -> Unit): IntArray defined in kotlin.collections
public inline fun LongArray.onEach(action: (Long) -> Unit): LongArray defined in kotlin.collections
public inline fun ShortArray.onEach(action: (Short) -> Unit): ShortArray defined in kotlin.collections
public inline fun UByteArray.onEach(action: (UByte) -> Unit): UByteArray defined in kotlin.collections
public inline fun UIntArray.onEach(action: (UInt) -> Unit): UIntArray defined in kotlin.collections
public inline fun ULongArray.onEach(action: (ULong) -> Unit): ULongArray defined in kotlin.collections
public inline fun UShortArray.onEach(action: (UShort) -> Unit): UShortArray defined in kotlin.collections
public fun <T> Sequence<TypeVariable(T)>.onEach(action: (TypeVariable(T)) -> Unit): Sequence<TypeVariable(T)> defined in kotlin.sequences
e: file:///***/generated_test/src/commonMain/kotlin/com/example/kotlin/api/apis/DefaultApi.kt:57:38 Unresolved reference: it
The generated API method looks like this (onEach is not supported since the file variable is not a collection):
open suspend fun uploadFile(file: io.ktor.client.request.forms.InputProvider? = null): HttpResponse<Unit> {
val localVariableAuthNames = listOf<String>()
val localVariableBody =
formData {
file?.onEach {
append("file[]", it)
}
}
...I'm a bit unsure what the expected output is, but the output when using v6.6.0 was this for the formData:
val localVariableBody =
formData {
file?.apply { append("file", file) }
}
I would guess this only supports a single file, though, unless InputProvider can hold multiple files.
Related issues/PRs
Suggest a fix
kalinjul