diff --git a/README.md b/README.md index 09b952dee03..39161f9efce 100644 --- a/README.md +++ b/README.md @@ -850,13 +850,14 @@ Swagger Codegen core team members are contributors who have been making signific |:-------------|:-------------| | ActionScript | | | C++ | | -| C# | @jimschubert (2016/05/01) | | +| C# | @jimschubert (2016/05/01) | | Clojure | @xhh (2016/05/01) | | Dart | | | Groovy | | | Go | @guohuang (2016/05/01) @neilotoole (2016/05/01) | | Java | @cbornet (2016/05/01) @xhh (2016/05/01) @epaul (2016/06/04) | | Java (Spring Cloud) | @cbornet (2016/07/19) | +| Kotlin | @jimschubert (2016/05/01) | | NodeJS/Javascript | @xhh (2016/05/01) | | ObjC | @mateuszmackowiak (2016/05/09) | | Perl | @wing328 (2016/05/01) | @@ -916,6 +917,7 @@ Here is a list of template creators: * Javascript/NodeJS: @jfiala * Javascript (Closure-annotated Angular) @achew22 * JMeter @davidkiss + * Kotlin @jimschubert * Perl: @wing328 * PHP (Guzzle): @baartosz * Swift: @tkqubo diff --git a/bin/kotlin-client-petstore.sh b/bin/kotlin-client-petstore.sh index fa017f1e8ef..1db46737d20 100755 --- a/bin/kotlin-client-petstore.sh +++ b/bin/kotlin-client-petstore.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="$@ generate -t modules/swagger-codegen/src/main/resources/kotlin-client -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l kotlin -o samples/client/kotlin" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/kotlin-client -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l kotlin -o samples/client/petstore/kotlin" java ${JAVA_OPTS} -jar ${executable} ${ags} diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/KotlinClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/KotlinClientCodegen.java index aa1a0039ded..1012e3039e5 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/KotlinClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/KotlinClientCodegen.java @@ -122,7 +122,7 @@ public class KotlinClientCodegen extends DefaultCodegen implements CodegenConfig typeMapping.put("date-time", "java.time.LocalDateTime"); typeMapping.put("date", "java.time.LocalDateTime"); typeMapping.put("file", "java.io.File"); - typeMapping.put("array", "kotlin.Array"); + typeMapping.put("array", "kotlin.collections.List"); typeMapping.put("list", "kotlin.collections.List"); typeMapping.put("map", "kotlin.collections.Map"); typeMapping.put("object", "kotlin.Any"); @@ -130,7 +130,7 @@ public class KotlinClientCodegen extends DefaultCodegen implements CodegenConfig typeMapping.put("Date", "java.time.LocalDateTime"); typeMapping.put("DateTime", "java.time.LocalDateTime"); - instantiationTypes.put("array", "arrayOf"); + instantiationTypes.put("array", "listOf"); instantiationTypes.put("list", "listOf"); instantiationTypes.put("map", "mapOf"); diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java index 23bf434bf3f..474806638d6 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/kotlin/KotlinClientCodegenModelTest.java @@ -104,10 +104,10 @@ public class KotlinClientCodegenModelTest { Assert.assertEquals(property.baseName, "examples"); Assert.assertEquals(property.getter, "getExamples"); Assert.assertEquals(property.setter, "setExamples"); - Assert.assertEquals(property.datatype, "kotlin.Array"); + Assert.assertEquals(property.datatype, "kotlin.collections.List"); Assert.assertEquals(property.name, "examples"); Assert.assertEquals(property.defaultValue, "null"); - Assert.assertEquals(property.baseType, "kotlin.Array"); + Assert.assertEquals(property.baseType, "kotlin.collections.List"); Assert.assertEquals(property.containerType, "array"); Assert.assertFalse(property.required); Assert.assertTrue(property.isContainer); diff --git a/new.sh b/new.sh index 8c71230d50a..cace3efcad3 100755 --- a/new.sh +++ b/new.sh @@ -160,7 +160,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="\${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="\$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l ${gen_name} -o samples/${gen_type}/${gen_name}" +ags="\$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l ${gen_name} -o samples/${gen_type}/petstore/${gen_name}" java \${JAVA_OPTS} -jar \${executable} \${ags} EOF diff --git a/samples/client/kotlin/build.gradle b/samples/client/kotlin/build.gradle deleted file mode 100644 index 1ae1ae99322..00000000000 --- a/samples/client/kotlin/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -group 'io.swagger' -version '1.0.0' - -task wrapper(type: Wrapper) { - gradleVersion = '3.3' - distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" -} - -buildscript { - ext.kotlin_version = '1.1.2' - - repositories { - mavenCentral() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - -apply plugin: 'kotlin' - -repositories { - mavenCentral() -} - -dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" - compile "com.squareup.moshi:moshi-kotlin:1.5.0" - compile "com.squareup.moshi:moshi-adapters:1.5.0" - compile "com.squareup.okhttp3:okhttp:3.8.0" - testCompile "io.kotlintest:kotlintest:2.0.2" -} \ No newline at end of file diff --git a/samples/client/kotlin/settings.gradle b/samples/client/kotlin/settings.gradle deleted file mode 100644 index 50b05bef95e..00000000000 --- a/samples/client/kotlin/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'kotlin-client' \ No newline at end of file diff --git a/samples/client/kotlin/.gitignore b/samples/client/petstore/kotlin/.gitignore similarity index 99% rename from samples/client/kotlin/.gitignore rename to samples/client/petstore/kotlin/.gitignore index fe1b206d040..2983e3c1db3 100644 --- a/samples/client/kotlin/.gitignore +++ b/samples/client/petstore/kotlin/.gitignore @@ -1,4 +1,4 @@ - +./bin/ # Created by https://www.gitignore.io/api/java,intellij,gradle ### Intellij ### diff --git a/samples/client/kotlin/.swagger-codegen-ignore b/samples/client/petstore/kotlin/.swagger-codegen-ignore similarity index 100% rename from samples/client/kotlin/.swagger-codegen-ignore rename to samples/client/petstore/kotlin/.swagger-codegen-ignore diff --git a/samples/client/kotlin/.swagger-codegen/VERSION b/samples/client/petstore/kotlin/.swagger-codegen/VERSION similarity index 100% rename from samples/client/kotlin/.swagger-codegen/VERSION rename to samples/client/petstore/kotlin/.swagger-codegen/VERSION diff --git a/samples/client/kotlin/README.md b/samples/client/petstore/kotlin/README.md similarity index 100% rename from samples/client/kotlin/README.md rename to samples/client/petstore/kotlin/README.md diff --git a/samples/client/kotlin/bin/build.gradle b/samples/client/petstore/kotlin/build.gradle similarity index 100% rename from samples/client/kotlin/bin/build.gradle rename to samples/client/petstore/kotlin/build.gradle diff --git a/samples/client/kotlin/gradle/wrapper/gradle-wrapper.jar b/samples/client/petstore/kotlin/gradle/wrapper/gradle-wrapper.jar similarity index 99% rename from samples/client/kotlin/gradle/wrapper/gradle-wrapper.jar rename to samples/client/petstore/kotlin/gradle/wrapper/gradle-wrapper.jar index 45ac8213b78..f1a1584ef4a 100644 Binary files a/samples/client/kotlin/gradle/wrapper/gradle-wrapper.jar and b/samples/client/petstore/kotlin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/client/kotlin/gradle/wrapper/gradle-wrapper.properties b/samples/client/petstore/kotlin/gradle/wrapper/gradle-wrapper.properties similarity index 86% rename from samples/client/kotlin/gradle/wrapper/gradle-wrapper.properties rename to samples/client/petstore/kotlin/gradle/wrapper/gradle-wrapper.properties index 1d03d7af2f3..09c0ff530a8 100644 --- a/samples/client/kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/samples/client/petstore/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Mon May 29 10:58:54 EDT 2017 +#Mon May 29 15:39:04 EDT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/samples/client/kotlin/gradlew b/samples/client/petstore/kotlin/gradlew similarity index 100% rename from samples/client/kotlin/gradlew rename to samples/client/petstore/kotlin/gradlew diff --git a/samples/client/kotlin/gradlew.bat b/samples/client/petstore/kotlin/gradlew.bat similarity index 100% rename from samples/client/kotlin/gradlew.bat rename to samples/client/petstore/kotlin/gradlew.bat diff --git a/samples/client/kotlin/bin/settings.gradle b/samples/client/petstore/kotlin/settings.gradle similarity index 100% rename from samples/client/kotlin/bin/settings.gradle rename to samples/client/petstore/kotlin/settings.gradle diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt similarity index 96% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt index 336843fceec..a01400aa9d9 100644 --- a/samples/client/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/PetApi.kt @@ -85,10 +85,10 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli * Finds Pets by status * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter - * @return kotlin.Array + * @return kotlin.collections.List */ @Suppress("UNCHECKED_CAST") - fun findPetsByStatus(status: kotlin.Array) : kotlin.Array { + fun findPetsByStatus(status: kotlin.collections.List) : kotlin.collections.List { val localVariableBody: kotlin.Any? = null val localVariableQuery: kotlin.collections.Map = mapOf("status" to status.joinToString(separator = collectionDelimiter("csv"))) val localVariableHeaders: kotlin.collections.Map = mapOf() @@ -98,13 +98,13 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli query = localVariableQuery, headers = localVariableHeaders ) - val response = request>( + val response = request>( localVariableConfig, localVariableBody ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array + ResponseType.Success -> (response as Success<*>).data as kotlin.collections.List ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -117,10 +117,10 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by - * @return kotlin.Array + * @return kotlin.collections.List */ @Suppress("UNCHECKED_CAST") - fun findPetsByTags(tags: kotlin.Array) : kotlin.Array { + fun findPetsByTags(tags: kotlin.collections.List) : kotlin.collections.List { val localVariableBody: kotlin.Any? = null val localVariableQuery: kotlin.collections.Map = mapOf("tags" to tags.joinToString(separator = collectionDelimiter("csv"))) val localVariableHeaders: kotlin.collections.Map = mapOf() @@ -130,13 +130,13 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli query = localVariableQuery, headers = localVariableHeaders ) - val response = request>( + val response = request>( localVariableConfig, localVariableBody ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array + ResponseType.Success -> (response as Success<*>).data as kotlin.collections.List ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/apis/StoreApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/StoreApi.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/apis/StoreApi.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/StoreApi.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt similarity index 98% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt index b61953eaa61..e703c71bcdd 100644 --- a/samples/client/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/apis/UserApi.kt @@ -54,7 +54,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl * @param body List of user object * @return void */ - fun createUsersWithArrayInput(body: kotlin.Array) : Unit { + fun createUsersWithArrayInput(body: kotlin.collections.List) : Unit { val localVariableBody: kotlin.Any? = body val localVariableQuery: kotlin.collections.Map = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() @@ -85,7 +85,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl * @param body List of user object * @return void */ - fun createUsersWithListInput(body: kotlin.Array) : Unit { + fun createUsersWithListInput(body: kotlin.collections.List) : Unit { val localVariableBody: kotlin.Any? = body val localVariableQuery: kotlin.collections.Map = mapOf() val localVariableHeaders: kotlin.collections.Map = mapOf() diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiInfrastructureResponse.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiInfrastructureResponse.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiInfrastructureResponse.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApplicationDelegates.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApplicationDelegates.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApplicationDelegates.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApplicationDelegates.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/Errors.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/Errors.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/Errors.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestConfig.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestConfig.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestConfig.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestMethod.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestMethod.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestMethod.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/RequestMethod.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ResponseExtensions.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ResponseExtensions.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ResponseExtensions.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ResponseExtensions.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/Serializer.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/infrastructure/Serializer.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/Serializer.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/models/ApiResponse.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/ApiResponse.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/models/ApiResponse.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/ApiResponse.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Category.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Category.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Category.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Category.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Order.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Order.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Order.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Order.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt similarity index 90% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt index 210d6258545..31842fa7499 100644 --- a/samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Pet.kt @@ -27,8 +27,8 @@ data class Pet ( val id: kotlin.Long?, val category: Category?, val name: kotlin.String, - val photoUrls: kotlin.Array, - val tags: kotlin.Array?, + val photoUrls: kotlin.collections.List, + val tags: kotlin.collections.List?, /* pet status in the store */ val status: kotlin.String? ) diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Tag.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Tag.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/models/Tag.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/Tag.kt diff --git a/samples/client/kotlin/src/main/kotlin/io/swagger/client/models/User.kt b/samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/User.kt similarity index 100% rename from samples/client/kotlin/src/main/kotlin/io/swagger/client/models/User.kt rename to samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/models/User.kt diff --git a/samples/client/petstore/kotlin/src/test/kotlin/io/swagger/client/functional/EvaluateTest.kt b/samples/client/petstore/kotlin/src/test/kotlin/io/swagger/client/functional/EvaluateTest.kt new file mode 100644 index 00000000000..8983641ce38 --- /dev/null +++ b/samples/client/petstore/kotlin/src/test/kotlin/io/swagger/client/functional/EvaluateTest.kt @@ -0,0 +1,35 @@ +package io.swagger.client.functional + +import io.kotlintest.matchers.should +import io.kotlintest.matchers.beGreaterThan +import io.kotlintest.specs.ShouldSpec +import io.swagger.client.apis.PetApi + +class EvaluateTest : ShouldSpec() { + init { + should("query against pet statuses") { + val api = PetApi() + val results = api.findPetsByStatus(listOf("available", "pending")) + + results.size should beGreaterThan(1) + } + +// TODO: Handle default (200) response +/* + should("post data (new pet)") { + val api = PetApi() + val pet = Pet( + id = 0, + name = "kotlin client test", + category = Category(0, "string"), + tags = listOf(Tag(0, "string")) + ) + val result = api.addPet(pet) + + result.name shouldBe(pet.name) + result.category shouldBe(pet.category) + result.tags shouldBe(pet.tags) + } +*/ + } +} \ No newline at end of file