From 035b465bd7b8bac63859f2ef1a67d0632009d792 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 4 Aug 2020 16:51:14 +0800 Subject: [PATCH 1/4] fix missing import for file --- .../codegen/languages/KotlinClientCodegen.java | 7 +++++++ .../kotlin-client/libraries/jvm-retrofit2/api.mustache | 8 +++++++- .../main/kotlin/org/openapitools/client/apis/PetApi.kt | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) 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 85a2956fc4f7..529f63276cd3 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 @@ -604,6 +604,13 @@ public Map postProcessOperationsWithModels(Map o } } + // 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 c15415189747..490abb2aa3bf 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 @@ -35,6 +35,12 @@ import io.reactivex.Completable {{/imports}} {{#operations}} +{{#x-kotlin-multipart-import}} +{{^isMultipart}} +import okhttp3.MultipartBody + +{{/isMultipart}} +{{/x-kotlin-multipart-import}} interface {{classname}} { {{#operation}} /** @@ -70,4 +76,4 @@ interface {{classname}} { {{/operation}} } -{{/operations}} \ No newline at end of file +{{/operations}} 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 f3f9c057d241..4d78248129cc 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 From 4b97b75d126d6ae96d14afa587db6bf7c13d7390 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 4 Aug 2020 16:56:28 +0800 Subject: [PATCH 2/4] test in shippable --- pom.xml | 1 + .../client/petstore/kotlin-retrofit2/pom.xml | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 samples/client/petstore/kotlin-retrofit2/pom.xml diff --git a/pom.xml b/pom.xml index 0b77ce578f6f..c49fbf7b701d 100644 --- a/pom.xml +++ b/pom.xml @@ -1360,6 +1360,7 @@ samples/client/petstore/erlang-proper samples/client/petstore/kotlin-multiplatform + samples/client/petstore/kotlin-retrofit2 samples/client/petstore/kotlin-jackson/ samples/client/petstore/kotlin-gson/ samples/client/petstore/kotlin-nonpublic/ diff --git a/samples/client/petstore/kotlin-retrofit2/pom.xml b/samples/client/petstore/kotlin-retrofit2/pom.xml new file mode 100644 index 000000000000..a2a34c203fa8 --- /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 + + + + + + + + From c357b3a4baec0c9f4ed1cc0510a0d6e221f004ef Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 4 Aug 2020 22:59:56 +0800 Subject: [PATCH 3/4] test retrofit2 fx3 kotlin sample --- pom.xml | 1 + .../src/main/kotlin/org/openapitools/client/apis/PetApi.kt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index c49fbf7b701d..d26e2db1ac1d 100644 --- a/pom.xml +++ b/pom.xml @@ -1361,6 +1361,7 @@ 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/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 d33f1a005402..b52cebf4c31e 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 From 422a8194dce972002080a039666eff70d1145266 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 5 Aug 2020 00:32:58 +0800 Subject: [PATCH 4/4] add pom.xml --- .../petstore/kotlin-retrofit2-rx3/pom.xml | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 samples/client/petstore/kotlin-retrofit2-rx3/pom.xml 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 000000000000..1ee09680f372 --- /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 + + + + + + + +