[Kotlin][Retrofit2] fix missing import for file (#7121)

* fix missing import for file

* test in shippable

* test retrofit2 fx3 kotlin sample

* add pom.xml
This commit is contained in:
William Cheng 2020-08-05 10:24:31 +08:00 committed by GitHub
parent 9f1d012d14
commit aa698633b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 112 additions and 1 deletions

View File

@ -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("/")) { if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/")) {
operation.path = operation.path.substring(1); operation.path = operation.path.substring(1);
} }

View File

@ -41,6 +41,12 @@ import io.reactivex.rxjava3.core.Completable;
{{/imports}} {{/imports}}
{{#operations}} {{#operations}}
{{#x-kotlin-multipart-import}}
{{^isMultipart}}
import okhttp3.MultipartBody
{{/isMultipart}}
{{/x-kotlin-multipart-import}}
interface {{classname}} { interface {{classname}} {
{{#operation}} {{#operation}}
/** /**

View File

@ -1360,6 +1360,8 @@
<module>samples/client/petstore/erlang-proper</module> <module>samples/client/petstore/erlang-proper</module>
<module>samples/client/petstore/kotlin-multiplatform</module> <module>samples/client/petstore/kotlin-multiplatform</module>
<!--<module>samples/client/petstore/kotlin/</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-jackson/</module>
<module>samples/client/petstore/kotlin-gson/</module> <module>samples/client/petstore/kotlin-gson/</module>
<module>samples/client/petstore/kotlin-nonpublic/</module> <module>samples/client/petstore/kotlin-nonpublic/</module>

View File

@ -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>

View File

@ -9,6 +9,8 @@ import io.reactivex.rxjava3.core.Completable;
import org.openapitools.client.models.ApiResponse import org.openapitools.client.models.ApiResponse
import org.openapitools.client.models.Pet import org.openapitools.client.models.Pet
import okhttp3.MultipartBody
interface PetApi { interface PetApi {
/** /**
* Add a new pet to the store * Add a new pet to the store

View File

@ -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>

View File

@ -8,6 +8,8 @@ import okhttp3.RequestBody
import org.openapitools.client.models.ApiResponse import org.openapitools.client.models.ApiResponse
import org.openapitools.client.models.Pet import org.openapitools.client.models.Pet
import okhttp3.MultipartBody
interface PetApi { interface PetApi {
/** /**
* Add a new pet to the store * Add a new pet to the store