diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java
index 6265bea2bdf..1ac723a984e 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java
@@ -627,6 +627,13 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
}
}
+ // import okhttp3.MultipartBody if any parameter is a file
+ for (CodegenParameter param : operation.allParams) {
+ if (Boolean.TRUE.equals(param.isFile)) {
+ operations.put("x-kotlin-multipart-import", true);
+ }
+ }
+
if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/")) {
operation.path = operation.path.substring(1);
}
diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache
index 99e6b204d0e..5bb18f913f1 100644
--- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache
+++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache
@@ -41,6 +41,12 @@ import io.reactivex.rxjava3.core.Completable;
{{/imports}}
{{#operations}}
+{{#x-kotlin-multipart-import}}
+{{^isMultipart}}
+import okhttp3.MultipartBody
+
+{{/isMultipart}}
+{{/x-kotlin-multipart-import}}
interface {{classname}} {
{{#operation}}
/**
@@ -76,4 +82,4 @@ interface {{classname}} {
{{/operation}}
}
-{{/operations}}
\ No newline at end of file
+{{/operations}}
diff --git a/pom.xml b/pom.xml
index 0b77ce578f6..d26e2db1ac1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1360,6 +1360,8 @@
samples/client/petstore/erlang-proper
samples/client/petstore/kotlin-multiplatform
+ samples/client/petstore/kotlin-retrofit2
+ samples/client/petstore/kotlin-retrofit2-rx3
samples/client/petstore/kotlin-jackson/
samples/client/petstore/kotlin-gson/
samples/client/petstore/kotlin-nonpublic/
diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/pom.xml b/samples/client/petstore/kotlin-retrofit2-rx3/pom.xml
new file mode 100644
index 00000000000..1ee09680f37
--- /dev/null
+++ b/samples/client/petstore/kotlin-retrofit2-rx3/pom.xml
@@ -0,0 +1,46 @@
+
+ 4.0.0
+ org.openapitools
+ KotlinRetrofit2Rx3PetstoreClientTests
+ pom
+ 1.0-SNAPSHOT
+ Kotlin Retrofit2 Rx3 Petstore Client
+
+
+
+ maven-dependency-plugin
+
+
+ package
+
+ copy-dependencies
+
+
+ ${project.build.directory}
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+
+ bundle-test
+ integration-test
+
+ exec
+
+
+ gradle
+
+ test
+
+
+
+
+
+
+
+
diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
index d33f1a00540..b52cebf4c31 100644
--- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
+++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
@@ -9,6 +9,8 @@ import io.reactivex.rxjava3.core.Completable;
import org.openapitools.client.models.ApiResponse
import org.openapitools.client.models.Pet
+import okhttp3.MultipartBody
+
interface PetApi {
/**
* Add a new pet to the store
diff --git a/samples/client/petstore/kotlin-retrofit2/pom.xml b/samples/client/petstore/kotlin-retrofit2/pom.xml
new file mode 100644
index 00000000000..a2a34c203fa
--- /dev/null
+++ b/samples/client/petstore/kotlin-retrofit2/pom.xml
@@ -0,0 +1,46 @@
+
+ 4.0.0
+ org.openapitools
+ KotlinRetrofit2PetstoreClientTests
+ pom
+ 1.0-SNAPSHOT
+ Kotlin Retrofit2 Petstore Client
+
+
+
+ maven-dependency-plugin
+
+
+ package
+
+ copy-dependencies
+
+
+ ${project.build.directory}
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+
+ bundle-test
+ integration-test
+
+ exec
+
+
+ gradle
+
+ test
+
+
+
+
+
+
+
+
diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
index f3f9c057d24..4d78248129c 100644
--- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
+++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/apis/PetApi.kt
@@ -8,6 +8,8 @@ import okhttp3.RequestBody
import org.openapitools.client.models.ApiResponse
import org.openapitools.client.models.Pet
+import okhttp3.MultipartBody
+
interface PetApi {
/**
* Add a new pet to the store