Skip to content

Commit 0e43b9c

Browse files
committed
update kotlin samples
1 parent ff663f1 commit 0e43b9c

3 files changed

Lines changed: 30 additions & 30 deletions

File tree

  • samples/client/petstore
    • kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/infrastructure
    • kotlin-jvm-ktor-jackson/src/main/kotlin/org/openapitools/client/infrastructure
    • kotlin-jvm-ktor-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure

samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import io.ktor.http.isSuccess
55
import io.ktor.util.reflect.TypeInfo
66
import io.ktor.util.reflect.typeInfo
77

8-
open class HttpResponse<T : Any>(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider<T>) {
8+
open class HttpResponse<T>(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider<T>) {
99
val status: Int = response.status.value
1010
val success: Boolean = response.status.isSuccess()
1111
val headers: Map<String, List<String>> = response.headers.mapEntries()
1212
suspend fun body(): T = provider.body(response)
13-
suspend fun <V : Any> typedBody(type: TypeInfo): V = provider.typedBody(response, type)
13+
suspend fun <V> typedBody(type: TypeInfo): V = provider.typedBody(response, type)
1414

1515
companion object {
1616
private fun Headers.mapEntries(): Map<String, List<String>> {
@@ -21,31 +21,31 @@ open class HttpResponse<T : Any>(val response: io.ktor.client.statement.HttpResp
2121
}
2222
}
2323

24-
interface BodyProvider<T : Any> {
24+
interface BodyProvider<T> {
2525
suspend fun body(response: io.ktor.client.statement.HttpResponse): T
26-
suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V
26+
suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V
2727
}
2828

29-
class TypedBodyProvider<T : Any>(private val type: TypeInfo) : BodyProvider<T> {
29+
class TypedBodyProvider<T>(private val type: TypeInfo) : BodyProvider<T> {
3030
@Suppress("UNCHECKED_CAST")
3131
override suspend fun body(response: io.ktor.client.statement.HttpResponse): T =
3232
response.call.body(type) as T
3333

3434
@Suppress("UNCHECKED_CAST")
35-
override suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
35+
override suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
3636
response.call.body(type) as V
3737
}
3838

39-
class MappedBodyProvider<S : Any, T : Any>(private val provider: BodyProvider<S>, private val block: S.() -> T) : BodyProvider<T> {
39+
class MappedBodyProvider<S, T>(private val provider: BodyProvider<S>, private val block: S.() -> T) : BodyProvider<T> {
4040
override suspend fun body(response: io.ktor.client.statement.HttpResponse): T =
4141
block(provider.body(response))
4242

43-
override suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
43+
override suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
4444
provider.typedBody(response, type)
4545
}
4646

47-
inline fun <reified T : Any> io.ktor.client.statement.HttpResponse.wrap(): HttpResponse<T> =
47+
inline fun <reified T> io.ktor.client.statement.HttpResponse.wrap(): HttpResponse<T> =
4848
HttpResponse(this, TypedBodyProvider(typeInfo<T>()))
4949

50-
fun <T : Any, V : Any> HttpResponse<T>.map(block: T.() -> V): HttpResponse<V> =
50+
fun <T, V> HttpResponse<T>.map(block: T.() -> V): HttpResponse<V> =
5151
HttpResponse(response, MappedBodyProvider(provider, block))

samples/client/petstore/kotlin-jvm-ktor-jackson/src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import io.ktor.http.isSuccess
55
import io.ktor.util.reflect.TypeInfo
66
import io.ktor.util.reflect.typeInfo
77

8-
open class HttpResponse<T : Any>(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider<T>) {
8+
open class HttpResponse<T>(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider<T>) {
99
val status: Int = response.status.value
1010
val success: Boolean = response.status.isSuccess()
1111
val headers: Map<String, List<String>> = response.headers.mapEntries()
1212
suspend fun body(): T = provider.body(response)
13-
suspend fun <V : Any> typedBody(type: TypeInfo): V = provider.typedBody(response, type)
13+
suspend fun <V> typedBody(type: TypeInfo): V = provider.typedBody(response, type)
1414

1515
companion object {
1616
private fun Headers.mapEntries(): Map<String, List<String>> {
@@ -21,31 +21,31 @@ open class HttpResponse<T : Any>(val response: io.ktor.client.statement.HttpResp
2121
}
2222
}
2323

24-
interface BodyProvider<T : Any> {
24+
interface BodyProvider<T> {
2525
suspend fun body(response: io.ktor.client.statement.HttpResponse): T
26-
suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V
26+
suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V
2727
}
2828

29-
class TypedBodyProvider<T : Any>(private val type: TypeInfo) : BodyProvider<T> {
29+
class TypedBodyProvider<T>(private val type: TypeInfo) : BodyProvider<T> {
3030
@Suppress("UNCHECKED_CAST")
3131
override suspend fun body(response: io.ktor.client.statement.HttpResponse): T =
3232
response.call.body(type) as T
3333

3434
@Suppress("UNCHECKED_CAST")
35-
override suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
35+
override suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
3636
response.call.body(type) as V
3737
}
3838

39-
class MappedBodyProvider<S : Any, T : Any>(private val provider: BodyProvider<S>, private val block: S.() -> T) : BodyProvider<T> {
39+
class MappedBodyProvider<S, T>(private val provider: BodyProvider<S>, private val block: S.() -> T) : BodyProvider<T> {
4040
override suspend fun body(response: io.ktor.client.statement.HttpResponse): T =
4141
block(provider.body(response))
4242

43-
override suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
43+
override suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
4444
provider.typedBody(response, type)
4545
}
4646

47-
inline fun <reified T : Any> io.ktor.client.statement.HttpResponse.wrap(): HttpResponse<T> =
47+
inline fun <reified T> io.ktor.client.statement.HttpResponse.wrap(): HttpResponse<T> =
4848
HttpResponse(this, TypedBodyProvider(typeInfo<T>()))
4949

50-
fun <T : Any, V : Any> HttpResponse<T>.map(block: T.() -> V): HttpResponse<V> =
50+
fun <T, V> HttpResponse<T>.map(block: T.() -> V): HttpResponse<V> =
5151
HttpResponse(response, MappedBodyProvider(provider, block))

samples/client/petstore/kotlin-jvm-ktor-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import io.ktor.http.isSuccess
55
import io.ktor.util.reflect.TypeInfo
66
import io.ktor.util.reflect.typeInfo
77

8-
open class HttpResponse<T : Any>(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider<T>) {
8+
open class HttpResponse<T>(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider<T>) {
99
val status: Int = response.status.value
1010
val success: Boolean = response.status.isSuccess()
1111
val headers: Map<String, List<String>> = response.headers.mapEntries()
1212
suspend fun body(): T = provider.body(response)
13-
suspend fun <V : Any> typedBody(type: TypeInfo): V = provider.typedBody(response, type)
13+
suspend fun <V> typedBody(type: TypeInfo): V = provider.typedBody(response, type)
1414

1515
companion object {
1616
private fun Headers.mapEntries(): Map<String, List<String>> {
@@ -21,31 +21,31 @@ open class HttpResponse<T : Any>(val response: io.ktor.client.statement.HttpResp
2121
}
2222
}
2323

24-
interface BodyProvider<T : Any> {
24+
interface BodyProvider<T> {
2525
suspend fun body(response: io.ktor.client.statement.HttpResponse): T
26-
suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V
26+
suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V
2727
}
2828

29-
class TypedBodyProvider<T : Any>(private val type: TypeInfo) : BodyProvider<T> {
29+
class TypedBodyProvider<T>(private val type: TypeInfo) : BodyProvider<T> {
3030
@Suppress("UNCHECKED_CAST")
3131
override suspend fun body(response: io.ktor.client.statement.HttpResponse): T =
3232
response.call.body(type) as T
3333

3434
@Suppress("UNCHECKED_CAST")
35-
override suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
35+
override suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
3636
response.call.body(type) as V
3737
}
3838

39-
class MappedBodyProvider<S : Any, T : Any>(private val provider: BodyProvider<S>, private val block: S.() -> T) : BodyProvider<T> {
39+
class MappedBodyProvider<S, T>(private val provider: BodyProvider<S>, private val block: S.() -> T) : BodyProvider<T> {
4040
override suspend fun body(response: io.ktor.client.statement.HttpResponse): T =
4141
block(provider.body(response))
4242

43-
override suspend fun <V : Any> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
43+
override suspend fun <V> typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V =
4444
provider.typedBody(response, type)
4545
}
4646

47-
inline fun <reified T : Any> io.ktor.client.statement.HttpResponse.wrap(): HttpResponse<T> =
47+
inline fun <reified T> io.ktor.client.statement.HttpResponse.wrap(): HttpResponse<T> =
4848
HttpResponse(this, TypedBodyProvider(typeInfo<T>()))
4949

50-
fun <T : Any, V : Any> HttpResponse<T>.map(block: T.() -> V): HttpResponse<V> =
50+
fun <T, V> HttpResponse<T>.map(block: T.() -> V): HttpResponse<V> =
5151
HttpResponse(response, MappedBodyProvider(provider, block))

0 commit comments

Comments
 (0)