Skip to content

Commit

Permalink
Code clean up (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso authored Apr 27, 2024
1 parent 9a98784 commit a127443
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 40 deletions.
10 changes: 7 additions & 3 deletions ktorfit-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("multiplatform")
id("maven-publish")
Expand All @@ -18,7 +22,7 @@ java {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

Expand Down Expand Up @@ -170,7 +174,7 @@ publishing {
}
}

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class) {
rootProject.the(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class).nodeVersion =
rootProject.plugins.withType(NodeJsRootPlugin::class) {
rootProject.the(NodeJsRootExtension::class).version =
"18.0.0"
}
2 changes: 1 addition & 1 deletion ktorfit-converters/call/api/android/call.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract interface class de/jensklingenberg/ktorfit/Callback {
public abstract fun onResponse (Ljava/lang/Object;Lio/ktor/client/statement/HttpResponse;)V
}

public final class de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public final class de/jensklingenberg/ktorfit/converter/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public fun <init> ()V
public fun requestParameterConverter (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Lde/jensklingenberg/ktorfit/converter/Converter$RequestParameterConverter;
public fun responseConverter (Lde/jensklingenberg/ktorfit/converter/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter;
Expand Down
2 changes: 1 addition & 1 deletion ktorfit-converters/call/api/jvm/call.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract interface class de/jensklingenberg/ktorfit/Callback {
public abstract fun onResponse (Ljava/lang/Object;Lio/ktor/client/statement/HttpResponse;)V
}

public final class de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public final class de/jensklingenberg/ktorfit/converter/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public fun <init> ()V
public fun requestParameterConverter (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Lde/jensklingenberg/ktorfit/converter/Converter$RequestParameterConverter;
public fun responseConverter (Lde/jensklingenberg/ktorfit/converter/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter;
Expand Down
7 changes: 5 additions & 2 deletions ktorfit-converters/call/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin

plugins {
kotlin("multiplatform")
id("maven-publish")
Expand Down Expand Up @@ -193,6 +196,6 @@ publishing {
}
}

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class) {
rootProject.the(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class).nodeVersion = "18.0.0"
rootProject.plugins.withType(NodeJsRootPlugin::class) {
rootProject.the(NodeJsRootExtension::class).version = "18.0.0"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package de.jensklingenberg.ktorfit.converter.builtin
package de.jensklingenberg.ktorfit.converter

import de.jensklingenberg.ktorfit.Call
import de.jensklingenberg.ktorfit.Callback
import de.jensklingenberg.ktorfit.Ktorfit
import de.jensklingenberg.ktorfit.converter.Converter
import de.jensklingenberg.ktorfit.converter.KtorfitResult
import de.jensklingenberg.ktorfit.converter.TypeData
import io.ktor.client.call.*
import io.ktor.client.statement.*
import kotlinx.coroutines.launch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import de.jensklingenberg.ktorfit.Call
import de.jensklingenberg.ktorfit.Callback
import de.jensklingenberg.ktorfit.Ktorfit
import de.jensklingenberg.ktorfit.converter.builtin.CallConverterFactory
import de.jensklingenberg.ktorfit.converter.CallConverterFactory
import de.jensklingenberg.ktorfit.converter.TypeData
import io.ktor.client.*
import io.ktor.client.engine.mock.*
Expand Down
2 changes: 1 addition & 1 deletion ktorfit-converters/flow/api/android/flow.api
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public final class de/jensklingenberg/ktorfit/converter/builtin/FlowConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public final class de/jensklingenberg/ktorfit/converter/FlowConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public fun <init> ()V
public fun requestParameterConverter (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Lde/jensklingenberg/ktorfit/converter/Converter$RequestParameterConverter;
public fun responseConverter (Lde/jensklingenberg/ktorfit/converter/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter;
Expand Down
2 changes: 1 addition & 1 deletion ktorfit-converters/flow/api/jvm/flow.api
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public final class de/jensklingenberg/ktorfit/converter/builtin/FlowConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public final class de/jensklingenberg/ktorfit/converter/FlowConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public fun <init> ()V
public fun requestParameterConverter (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Lde/jensklingenberg/ktorfit/converter/Converter$RequestParameterConverter;
public fun responseConverter (Lde/jensklingenberg/ktorfit/converter/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter;
Expand Down
7 changes: 5 additions & 2 deletions ktorfit-converters/flow/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin

plugins {
kotlin("multiplatform")
id("maven-publish")
Expand Down Expand Up @@ -183,6 +186,6 @@ publishing {
}
}

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class) {
rootProject.the(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class).nodeVersion = "18.0.0"
rootProject.plugins.withType(NodeJsRootPlugin::class) {
rootProject.the(NodeJsRootExtension::class).version = "18.0.0"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package de.jensklingenberg.ktorfit.converter.builtin
package de.jensklingenberg.ktorfit.converter

import de.jensklingenberg.ktorfit.Ktorfit
import de.jensklingenberg.ktorfit.converter.Converter
import de.jensklingenberg.ktorfit.converter.KtorfitResult
import de.jensklingenberg.ktorfit.converter.TypeData
import io.ktor.client.call.*
import io.ktor.client.statement.*
import kotlinx.coroutines.flow.Flow
Expand Down
7 changes: 4 additions & 3 deletions ktorfit-converters/response/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin

plugins {
kotlin("multiplatform")
Expand Down Expand Up @@ -193,6 +194,6 @@ publishing {
}
}

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class) {
rootProject.the(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class).nodeVersion = "18.0.0"
rootProject.plugins.withType(NodeJsRootPlugin::class) {
rootProject.the(NodeJsRootExtension::class).version = "18.0.0"
}
1 change: 1 addition & 0 deletions ktorfit-lib-core/api/android/ktorfit-lib-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public final class de/jensklingenberg/ktorfit/converter/TypeData {

public final class de/jensklingenberg/ktorfit/converter/TypeData$Companion {
public final fun createTypeData (Ljava/lang/String;Lio/ktor/util/reflect/TypeInfo;)Lde/jensklingenberg/ktorfit/converter/TypeData;
public static synthetic fun createTypeData$default (Lde/jensklingenberg/ktorfit/converter/TypeData$Companion;Ljava/lang/String;Lio/ktor/util/reflect/TypeInfo;ILjava/lang/Object;)Lde/jensklingenberg/ktorfit/converter/TypeData;
}

public abstract interface annotation class de/jensklingenberg/ktorfit/internal/InternalKtorfitApi : java/lang/annotation/Annotation {
Expand Down
1 change: 1 addition & 0 deletions ktorfit-lib-core/api/jvm/ktorfit-lib-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public final class de/jensklingenberg/ktorfit/converter/TypeData {

public final class de/jensklingenberg/ktorfit/converter/TypeData$Companion {
public final fun createTypeData (Ljava/lang/String;Lio/ktor/util/reflect/TypeInfo;)Lde/jensklingenberg/ktorfit/converter/TypeData;
public static synthetic fun createTypeData$default (Lde/jensklingenberg/ktorfit/converter/TypeData$Companion;Ljava/lang/String;Lio/ktor/util/reflect/TypeInfo;ILjava/lang/Object;)Lde/jensklingenberg/ktorfit/converter/TypeData;
}

public abstract interface annotation class de/jensklingenberg/ktorfit/internal/InternalKtorfitApi : java/lang/annotation/Annotation {
Expand Down
7 changes: 5 additions & 2 deletions ktorfit-lib-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin

plugins {
kotlin("multiplatform")
alias(libs.plugins.kspPlugin)
Expand Down Expand Up @@ -214,8 +217,8 @@ publishing {
}
}

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class) {
rootProject.the(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class).nodeVersion = "18.0.0"
rootProject.plugins.withType(NodeJsRootPlugin::class) {
rootProject.the(NodeJsRootExtension::class).version = "18.0.0"
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,23 @@ public interface Converter<F, T> {
/**
* Return a [ResponseConverter] that can handle [typeData] or else null
*/
public fun responseConverter(typeData: TypeData, ktorfit: Ktorfit): ResponseConverter<HttpResponse, *>? {
return null
}
public fun responseConverter(typeData: TypeData, ktorfit: Ktorfit): ResponseConverter<HttpResponse, *>? = null

/**
* Return a [RequestParameterConverter] that can handle [parameterType] and [requestType] or else null
*/
public fun requestParameterConverter(
parameterType: KClass<*>,
requestType: KClass<*>
): RequestParameterConverter? {
return null
}
): RequestParameterConverter? = null

/**
* Return a [SuspendResponseConverter] that can handle [typeData] or else null
*/
public fun suspendResponseConverter(
typeData: TypeData,
ktorfit: Ktorfit
): SuspendResponseConverter<HttpResponse, *>? {
return null
}
): SuspendResponseConverter<HttpResponse, *>? = null
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public data class TypeData(
public val isNullable: Boolean = typeInfo.kotlinType?.isMarkedNullable ?: false,
) {
public companion object {
public fun createTypeData(qualifiedTypename: String, typeInfo: TypeInfo): TypeData {
public fun createTypeData(qualifiedTypename: String = "", typeInfo: TypeInfo): TypeData {
val typeArgument = qualifiedTypename.substringAfter("<").substringBeforeLast(">")
val split = typeArgument.split(",")
val args = typeInfo.kotlinType?.arguments?.mapIndexed { index, kTypeProjection ->
val cleaned = split[index].trim()
val cleaned = split.getOrNull(index)?.trim() ?: ""

val modelKType = kTypeProjection.type
val modelClass = (modelKType?.classifier as? KClass<*>?)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class RequestDataTest {
class TypeDataTest {

@Test
fun testTypeDataCreator() {
Expand All @@ -19,4 +19,15 @@ class RequestDataTest {

}

@Test
fun testTypeDataCreatorWithEmptyQualifiedName() {

val typeData = TypeData.createTypeData("", typeInfo<Map<String, Int?>>())

assertEquals("", typeData.qualifiedName)
assertTrue(typeData.typeInfo.type == Map::class)
assertTrue(typeData.typeArgs[0].typeInfo.type == String::class)

}

}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.model

import com.example.api.JsonPlaceHolderApi
import de.jensklingenberg.ktorfit.converter.builtin.CallConverterFactory
import de.jensklingenberg.ktorfit.converter.CallConverterFactory
import de.jensklingenberg.ktorfit.ktorfit
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.example.api.JsonPlaceHolderApi
import com.example.model.ExampleApi
import com.example.model.MyOwnResponse
import com.example.model.MyOwnResponseConverterFactory
import de.jensklingenberg.ktorfit.converter.builtin.CallConverterFactory
import de.jensklingenberg.ktorfit.converter.builtin.FlowConverterFactory
import de.jensklingenberg.ktorfit.converter.CallConverterFactory
import de.jensklingenberg.ktorfit.converter.FlowConverterFactory
import de.jensklingenberg.ktorfit.ktorfit
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
Expand Down

0 comments on commit a127443

Please sign in to comment.