Skip to content

Commit aa69863

Browse files
authored
[Kotlin][Retrofit2] fix missing import for file (#7121)
* fix missing import for file * test in shippable * test retrofit2 fx3 kotlin sample * add pom.xml
1 parent 9f1d012 commit aa69863

File tree

7 files changed

+112
-1
lines changed

7 files changed

+112
-1
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
627627
}
628628
}
629629

630+
// import okhttp3.MultipartBody if any parameter is a file
631+
for (CodegenParameter param : operation.allParams) {
632+
if (Boolean.TRUE.equals(param.isFile)) {
633+
operations.put("x-kotlin-multipart-import", true);
634+
}
635+
}
636+
630637
if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/")) {
631638
operation.path = operation.path.substring(1);
632639
}

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ import io.reactivex.rxjava3.core.Completable;
4141
{{/imports}}
4242

4343
{{#operations}}
44+
{{#x-kotlin-multipart-import}}
45+
{{^isMultipart}}
46+
import okhttp3.MultipartBody
47+
48+
{{/isMultipart}}
49+
{{/x-kotlin-multipart-import}}
4450
interface {{classname}} {
4551
{{#operation}}
4652
/**
@@ -76,4 +82,4 @@ interface {{classname}} {
7682

7783
{{/operation}}
7884
}
79-
{{/operations}}
85+
{{/operations}}

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,8 @@
13601360
<module>samples/client/petstore/erlang-proper</module>
13611361
<module>samples/client/petstore/kotlin-multiplatform</module>
13621362
<!--<module>samples/client/petstore/kotlin/</module>-->
1363+
<module>samples/client/petstore/kotlin-retrofit2</module>
1364+
<module>samples/client/petstore/kotlin-retrofit2-rx3</module>
13631365
<module>samples/client/petstore/kotlin-jackson/</module>
13641366
<module>samples/client/petstore/kotlin-gson/</module>
13651367
<module>samples/client/petstore/kotlin-nonpublic/</module>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.openapitools</groupId>
4+
<artifactId>KotlinRetrofit2Rx3PetstoreClientTests</artifactId>
5+
<packaging>pom</packaging>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>Kotlin Retrofit2 Rx3 Petstore Client</name>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<artifactId>maven-dependency-plugin</artifactId>
12+
<executions>
13+
<execution>
14+
<phase>package</phase>
15+
<goals>
16+
<goal>copy-dependencies</goal>
17+
</goals>
18+
<configuration>
19+
<outputDirectory>${project.build.directory}</outputDirectory>
20+
</configuration>
21+
</execution>
22+
</executions>
23+
</plugin>
24+
<plugin>
25+
<groupId>org.codehaus.mojo</groupId>
26+
<artifactId>exec-maven-plugin</artifactId>
27+
<version>1.2.1</version>
28+
<executions>
29+
<execution>
30+
<id>bundle-test</id>
31+
<phase>integration-test</phase>
32+
<goals>
33+
<goal>exec</goal>
34+
</goals>
35+
<configuration>
36+
<executable>gradle</executable>
37+
<arguments>
38+
<argument>test</argument>
39+
</arguments>
40+
</configuration>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
</project>

samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import io.reactivex.rxjava3.core.Completable;
99
import org.openapitools.client.models.ApiResponse
1010
import org.openapitools.client.models.Pet
1111

12+
import okhttp3.MultipartBody
13+
1214
interface PetApi {
1315
/**
1416
* Add a new pet to the store
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.openapitools</groupId>
4+
<artifactId>KotlinRetrofit2PetstoreClientTests</artifactId>
5+
<packaging>pom</packaging>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>Kotlin Retrofit2 Petstore Client</name>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<artifactId>maven-dependency-plugin</artifactId>
12+
<executions>
13+
<execution>
14+
<phase>package</phase>
15+
<goals>
16+
<goal>copy-dependencies</goal>
17+
</goals>
18+
<configuration>
19+
<outputDirectory>${project.build.directory}</outputDirectory>
20+
</configuration>
21+
</execution>
22+
</executions>
23+
</plugin>
24+
<plugin>
25+
<groupId>org.codehaus.mojo</groupId>
26+
<artifactId>exec-maven-plugin</artifactId>
27+
<version>1.2.1</version>
28+
<executions>
29+
<execution>
30+
<id>bundle-test</id>
31+
<phase>integration-test</phase>
32+
<goals>
33+
<goal>exec</goal>
34+
</goals>
35+
<configuration>
36+
<executable>gradle</executable>
37+
<arguments>
38+
<argument>test</argument>
39+
</arguments>
40+
</configuration>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
</project>

samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/apis/PetApi.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import okhttp3.RequestBody
88
import org.openapitools.client.models.ApiResponse
99
import org.openapitools.client.models.Pet
1010

11+
import okhttp3.MultipartBody
12+
1113
interface PetApi {
1214
/**
1315
* Add a new pet to the store

0 commit comments

Comments
 (0)