Skip to content

Commit

Permalink
[Kotlin][Retrofit2] fix missing import for file (#7121)
Browse files Browse the repository at this point in the history
* fix missing import for file

* test in shippable

* test retrofit2 fx3 kotlin sample

* add pom.xml
  • Loading branch information
wing328 authored Aug 5, 2020
1 parent 9f1d012 commit aa69863
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
/**
Expand Down Expand Up @@ -76,4 +82,4 @@ interface {{classname}} {

{{/operation}}
}
{{/operations}}
{{/operations}}
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,8 @@
<module>samples/client/petstore/erlang-proper</module>
<module>samples/client/petstore/kotlin-multiplatform</module>
<!--<module>samples/client/petstore/kotlin/</module>-->
<module>samples/client/petstore/kotlin-retrofit2</module>
<module>samples/client/petstore/kotlin-retrofit2-rx3</module>
<module>samples/client/petstore/kotlin-jackson/</module>
<module>samples/client/petstore/kotlin-gson/</module>
<module>samples/client/petstore/kotlin-nonpublic/</module>
Expand Down
46 changes: 46 additions & 0 deletions samples/client/petstore/kotlin-retrofit2-rx3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>KotlinRetrofit2Rx3PetstoreClientTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Kotlin Retrofit2 Rx3 Petstore Client</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>bundle-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>gradle</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions samples/client/petstore/kotlin-retrofit2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>KotlinRetrofit2PetstoreClientTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Kotlin Retrofit2 Petstore Client</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>bundle-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>gradle</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aa69863

Please sign in to comment.