Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from SchibstedSpain/query-param-added
Browse files Browse the repository at this point in the history
[Issue #14] Query parameters now included on interface
  • Loading branch information
ferranpons authored Oct 30, 2018
2 parents 29e3114 + 17a1fd1 commit d26c1cd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 39 deletions.
36 changes: 18 additions & 18 deletions Protein.ipr
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.squareup.retrofit2/retrofit/2.4.0/451207353948708405a08287e2a315c3f23553fe/retrofit-2.4.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Gradle: com.squareup:kotlinpoet:1.0.0-RC1">
<library name="Gradle: com.squareup:kotlinpoet:1.0.0-RC2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.squareup/kotlinpoet/1.0.0-RC1/f30a5a448131ec418f34f4a29c0753f89387bb9/kotlinpoet-1.0.0-RC1.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.squareup/kotlinpoet/1.0.0-RC2/e2b1331da63dff4701cd523ab6ea2f3aadac1e71/kotlinpoet-1.0.0-RC2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.squareup/kotlinpoet/1.0.0-RC1/c87efb101a89fee0ec979519eacaa52bd10d8c02/kotlinpoet-1.0.0-RC1-sources.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.squareup/kotlinpoet/1.0.0-RC2/dcfb724ff7d15f285c6cc77a3f57481fcd27546d/kotlinpoet-1.0.0-RC2-sources.jar!/" />
</SOURCES>
</library>
<library name="Gradle: commons-io:commons-io:2.5">
Expand Down Expand Up @@ -292,49 +292,49 @@
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b/hamcrest-core-1.3-sources.jar!/" />
</SOURCES>
</library>
<library name="Gradle: org.jetbrains.kotlin:kotlin-reflect:1.2.50">
<library name="Gradle: org.jetbrains.kotlin:kotlin-reflect:1.2.71">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.50/9fab8887f91c8e17cce1a7522f45dc25976e57b9/kotlin-reflect-1.2.50.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.71/7512db3b3182753bd2e48ce8d345abbadc40fe6b/kotlin-reflect-1.2.71.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.50/752ab51766af77ac8480940230438901b11ccc51/kotlin-reflect-1.2.50-sources.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.71/837bf519e19ab718239e01223104869a40eab8b6/kotlin-reflect-1.2.71-sources.jar!/" />
</SOURCES>
</library>
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71" type="kotlin.common">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.3.0" type="kotlin.common">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.71/ba18ca1aa0e40eb6f1865b324af2f4cbb691c1ec/kotlin-stdlib-common-1.2.71.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.0/84a2e0288dc17cd64d692eb1e5e0de8cd5ff0846/kotlin-stdlib-common-1.3.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.71/ff62b6a76e3200cac3d7df0859d7665fe6d54955/kotlin-stdlib-common-1.2.71-sources.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.0/8bee30ce9d075088b3d590488a270e2c3ea39b3a/kotlin-stdlib-common-1.3.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.0">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.71/4ce93f539e2133f172f1167291a911f83400a5d0/kotlin-stdlib-jdk7-1.2.71.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.0/683e04a4e7f17437d7e1390480f312e122e42e9e/kotlin-stdlib-jdk7-1.3.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.71/1e054c1ef9afdfc7c79bc09dd5eed35791cef7a2/kotlin-stdlib-jdk7-1.2.71-sources.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.0/eb969cd43a30a1207d2c0fc3a2f933906ccee70a/kotlin-stdlib-jdk7-1.3.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.71">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.0">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.2.71/5470d1f752cd342edb77e1062bac07e838d2cea4/kotlin-stdlib-jdk8-1.2.71.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.0/7157cc6bc26328e2e97723d65d4ed7d7eddf603b/kotlin-stdlib-jdk8-1.3.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.2.71/f3016e6e03b6a6adb777b403d856e0f2c36ea646/kotlin-stdlib-jdk8-1.2.71-sources.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.0/21664c3fe18b12a644c20a0c3094482bbb2b9599/kotlin-stdlib-jdk8-1.3.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.2.71">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.3.0">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.71/d9717625bb3c731561251f8dd2c67a1011d6764c/kotlin-stdlib-1.2.71.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.0/a134b0cfe9bb44f98b0b3e889cda07923eea9428/kotlin-stdlib-1.3.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.71/2e8041d08283cbbb58ad131617486fc6449f6c85/kotlin-stdlib-1.2.71-sources.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.0/98515ba3feb571f93b923e61f643bdaed59d14ac/kotlin-stdlib-1.3.0-sources.jar!/" />
</SOURCES>
</library>
<library name="Gradle: org.jetbrains.kotlin:kotlin-test-junit:1.1.3-2">
Expand Down
38 changes: 25 additions & 13 deletions src/main/kotlin/protein/kotlinbuilders/KotlinApiBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.swagger.models.Swagger
import io.swagger.models.parameters.BodyParameter
import io.swagger.models.parameters.Parameter
import io.swagger.models.parameters.PathParameter
import io.swagger.models.parameters.QueryParameter
import io.swagger.models.properties.ArrayProperty
import io.swagger.models.properties.Property
import io.swagger.models.properties.RefProperty
Expand All @@ -30,12 +31,13 @@ import io.swagger.parser.SwaggerParser
import protein.common.StorageUtils
import protein.tracking.ErrorTracking
import retrofit2.http.Body
import retrofit2.http.Path
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PUT
import retrofit2.http.POST
import retrofit2.http.PATCH
import retrofit2.http.DELETE
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query
import java.io.FileNotFoundException
import java.lang.IllegalStateException
import java.net.UnknownHostException
Expand Down Expand Up @@ -260,15 +262,25 @@ class KotlinApiBuilder(
): Iterable<ParameterSpec> {
val methodParameters = ArrayList<ParameterSpec>()
for (parameter in operation.value.parameters) {
if (parameter.`in` == "body") {
val bodyParameterSpec: ParameterSpec = getBodyParameterSpec(parameter)
methodParameters.add(bodyParameterSpec)
} else if (parameter.`in` == "path") {
val pathParameterSpec =
ParameterSpec.builder(parameter.name, getKotlinClassTypeName((parameter as PathParameter).type))
.addAnnotation(
AnnotationSpec.builder(Path::class).addMember("\"${parameter.name}\"").build()).build()
methodParameters.add(pathParameterSpec)
when (parameter.`in`) {
"body" -> {
val bodyParameterSpec: ParameterSpec = getBodyParameterSpec(parameter)
methodParameters.add(bodyParameterSpec)
}
"path" -> {
val pathParameterSpec =
ParameterSpec.builder(parameter.name, getKotlinClassTypeName((parameter as PathParameter).type))
.addAnnotation(
AnnotationSpec.builder(Path::class).addMember("\"${parameter.name}\"").build()).build()
methodParameters.add(pathParameterSpec)
}
"query" -> {
val queryParameterSpec =
ParameterSpec.builder(parameter.name, getKotlinClassTypeName((parameter as QueryParameter).type))
.addAnnotation(
AnnotationSpec.builder(Query::class).addMember("\"${parameter.name}\"").build()).build()
methodParameters.add(queryParameterSpec)
}
}
}
return methodParameters
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/KotlinApiBuilderShould.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config.ConfigurationForTests
import junit.framework.Assert.assertEquals
import junit.framework.TestCase.assertEquals
import mocks.OPENSTF_INTERFACE_MOCK
import mocks.PET_STORE_INTERFACE_MOCK
import org.junit.Test
Expand Down
9 changes: 5 additions & 4 deletions src/test/kotlin/mocks/openstf_code_generated_mocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ const val OPENSTF_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
"import retrofit2.http.GET\n" +
"import retrofit2.http.POST\n" +
"import retrofit2.http.Path\n" +
"import retrofit2.http.Query\n" +
"\n" +
"interface componentNameApiInterface {\n" +
" @GET(\"/user\")\n" +
" fun getUser(): Single<UserResponse>\n" +
"\n" +
" @GET(\"/user/devices\")\n" +
" fun getUserDevices(): Single<DeviceListResponse>\n" +
" fun getUserDevices(@Query(\"fields\") fields: String): Single<DeviceListResponse>\n" +
"\n" +
" @POST(\"/user/devices\")\n" +
" fun addUserDevice(@Body device: AddUserDevicePayload): Completable\n" +
"\n" +
" @GET(\"/user/devices/{serial}\")\n" +
" fun getUserDeviceBySerial(@Path(\"serial\") serial: String): Single<DeviceResponse>\n" +
" fun getUserDeviceBySerial(@Path(\"serial\") serial: String, @Query(\"fields\") fields: String): Single<DeviceResponse>\n" +
"\n" +
" @DELETE(\"/user/devices/{serial}\")\n" +
" fun deleteUserDeviceBySerial(@Path(\"serial\") serial: String): Completable\n" +
Expand All @@ -36,8 +37,8 @@ const val OPENSTF_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" fun getUserAccessTokens(): Single<AccessTokensResponse>\n" +
"\n" +
" @GET(\"/devices\")\n" +
" fun getDevices(): Single<DeviceListResponse>\n" +
" fun getDevices(@Query(\"fields\") fields: String): Single<DeviceListResponse>\n" +
"\n" +
" @GET(\"/devices/{serial}\")\n" +
" fun getDeviceBySerial(@Path(\"serial\") serial: String): Single<DeviceResponse>\n" +
" fun getDeviceBySerial(@Path(\"serial\") serial: String, @Query(\"fields\") fields: String): Single<DeviceResponse>\n" +
"}\n"
7 changes: 4 additions & 3 deletions src/test/kotlin/mocks/pet_store_code_generated_mocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const val PET_STORE_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
"import retrofit2.http.POST\n" +
"import retrofit2.http.PUT\n" +
"import retrofit2.http.Path\n" +
"import retrofit2.http.Query\n" +
"\n" +
"interface componentNameApiInterface {\n" +
" @PUT(\"/pet\")\n" +
Expand All @@ -20,10 +21,10 @@ const val PET_STORE_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" fun addPet(@Body body: Pet): Completable\n" +
"\n" +
" @GET(\"/pet/findByStatus\")\n" +
" fun findPetsByStatus(): Single<List<Pet>>\n" +
" fun findPetsByStatus(@Query(\"status\") status: List): Single<List<Pet>>\n" +
"\n" +
" @GET(\"/pet/findByTags\")\n" +
" fun findPetsByTags(): Single<List<Pet>>\n" +
" fun findPetsByTags(@Query(\"tags\") tags: List): Single<List<Pet>>\n" +
"\n" +
" @GET(\"/pet/{petId}\")\n" +
" fun getPetById(@Path(\"petId\") petId: Int): Single<Pet>\n" +
Expand Down Expand Up @@ -59,7 +60,7 @@ const val PET_STORE_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" fun createUsersWithListInput(@Body body: Body): Completable\n" +
"\n" +
" @GET(\"/user/login\")\n" +
" fun loginUser(): Completable\n" +
" fun loginUser(@Query(\"username\") username: String, @Query(\"password\") password: String): Completable\n" +
"\n" +
" @GET(\"/user/logout\")\n" +
" fun logoutUser(): Completable\n" +
Expand Down

0 comments on commit d26c1cd

Please sign in to comment.