forked from loafle/openapi-generator-original
Kotlin client lists (#5729)
* [kotlin] array->List instead of Array Serialization to/from primitive arrays can cause issues with valid responses. This commit considers swagger 'array' types as 'List' which, although not as memory efficient should provide a cleaner interface for users (and avoid serialization issues). Also, updates README.md to list new generator and excludes folder at samples/client/kotlin/bin/, which is not used. * [kotlin] Move sample under conventional directory samples/client/kotlin/ -> samples/client/petstore/kotlin/ Updated new.sh to generate client/server/docs into similar structure. Current documentation generators (cwiki, html, html.md, html2) aren't following a convention like client/server generators.
This commit is contained in:
parent
9282098d72
commit
23cf641e8a
@ -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
|
||||
|
@ -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}
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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<kotlin.String>");
|
||||
Assert.assertEquals(property.datatype, "kotlin.collections.List<kotlin.String>");
|
||||
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);
|
||||
|
2
new.sh
2
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
|
||||
|
@ -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"
|
||||
}
|
@ -1 +0,0 @@
|
||||
rootProject.name = 'kotlin-client'
|
@ -1,4 +1,4 @@
|
||||
|
||||
./bin/
|
||||
# Created by https://www.gitignore.io/api/java,intellij,gradle
|
||||
|
||||
### Intellij ###
|
Binary file not shown.
@ -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
|
@ -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<Pet>
|
||||
* @return kotlin.collections.List<Pet>
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun findPetsByStatus(status: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
||||
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf("status" to status.joinToString(separator = collectionDelimiter("csv")))
|
||||
val localVariableHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf()
|
||||
@ -98,13 +98,13 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val response = request<kotlin.Array<Pet>>(
|
||||
val response = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (response.responseType) {
|
||||
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
|
||||
ResponseType.Success -> (response as Success<*>).data as kotlin.collections.List<Pet>
|
||||
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<Pet>
|
||||
* @return kotlin.collections.List<Pet>
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun findPetsByTags(tags: kotlin.Array<kotlin.String>) : kotlin.Array<Pet> {
|
||||
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>) : kotlin.collections.List<Pet> {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf("tags" to tags.joinToString(separator = collectionDelimiter("csv")))
|
||||
val localVariableHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf()
|
||||
@ -130,13 +130,13 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val response = request<kotlin.Array<Pet>>(
|
||||
val response = request<kotlin.collections.List<Pet>>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (response.responseType) {
|
||||
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
|
||||
ResponseType.Success -> (response as Success<*>).data as kotlin.collections.List<Pet>
|
||||
ResponseType.Informational -> TODO()
|
||||
ResponseType.Redirection -> TODO()
|
||||
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
|
@ -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<User>) : Unit {
|
||||
fun createUsersWithArrayInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf()
|
||||
val localVariableHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = 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<User>) : Unit {
|
||||
fun createUsersWithListInput(body: kotlin.collections.List<User>) : Unit {
|
||||
val localVariableBody: kotlin.Any? = body
|
||||
val localVariableQuery: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf()
|
||||
val localVariableHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = mapOf()
|
@ -27,8 +27,8 @@ data class Pet (
|
||||
val id: kotlin.Long?,
|
||||
val category: Category?,
|
||||
val name: kotlin.String,
|
||||
val photoUrls: kotlin.Array<kotlin.String>,
|
||||
val tags: kotlin.Array<Tag>?,
|
||||
val photoUrls: kotlin.collections.List<kotlin.String>,
|
||||
val tags: kotlin.collections.List<Tag>?,
|
||||
/* pet status in the store */
|
||||
val status: kotlin.String?
|
||||
)
|
@ -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)
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user