diff --git a/docs/architecture.md b/docs/architecture.md index 66ea32ec2..8f3451147 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -28,28 +28,29 @@ Let`s say we have a interface like this. At compile time Ktorfit/KSP checks for all functions that are annotated with Ktorfit annotations like @GET. Then it looks at the parent interfaces of that functions and generates, the source code of a Kotlin class that implements the interface. The classes are named like the interfaces but with an underscore at the beginning and "Impl" at the end, and they have the same package as the interfaces. In this case a class named _ExampleApiImpl will be generated. -The class will also implement **KtorfitService**. The setClient() function will be used to add the http client at runtime. ```kotlin @OptIn(InternalKtorfitApi::class) -public class _ExampleApiImpl : ExampleApi, KtorfitService { - public override lateinit var ktorfitClient: Client +public class _ExampleApiImpl( + private val _ktorfit: Ktorfit, +) : ExampleApi { + public val _converter: KtorfitConverterHelper = KtorfitConverterHelper(_ktorfit) - public override suspend fun exampleGet(): String { + override suspend fun exampleGet(): People { val _ext: HttpRequestBuilder.() -> Unit = { method = HttpMethod.parse("GET") - url(ktorfitClient.baseUrl + "/test") + url{ + takeFrom(_ktorfit.baseUrl + "/test") + } } - val _requestData = RequestData(returnTypeData = TypeData("kotlin.String"), - requestTypeInfo = typeInfo(), - returnTypeInfo = typeInfo(), - ktorfitRequestBuilder = _ext) + val _typeData = TypeData.createTypeData(qualifiedTypename = "com.example.model.People", + typeInfo = typeInfo()) - return ktorfitClient.suspendRequest(_requestData)!! + return _converter.suspendRequest(_typeData,_ext)!! } } -public fun Ktorfit.createExampleApi(): ExampleApi = this.create(_ExampleApiImpl()) +public fun Ktorfit.createExampleApi(): ExampleApi = this.create(_ExampleApiImpl(this)) ``` The next part is the compiler plugin which is added by the gradle plugin. @@ -64,18 +65,16 @@ val api = jvmKtorfit.create() will be transformed to: ```kotlin -val api = jvmKtorfit.create(_ExampleApiImpl()) +val api = jvmKtorfit.create(_ExampleApiImpl(jvmKtorfit)) ``` -When the create() function is used, the object is cast to a KtorfitService and the client will be added. -Then it is cast to requested type < T > +The create() function is used, checks that the compiler plugin replaced the default value ```kotlin -fun create(ktorfitService: KtorfitService = DefaultKtorfitService()): T { - if (ktorfitService is DefaultKtorfitService) { - throw IllegalArgumentException("You need to enable the Ktorfit Gradle Plugin") - } - ktorfitService.setClient(KtorfitClient(this)) - return ktorfitService as T +public fun create(data: T? = null): T { + if (data == null) { + throw IllegalArgumentException(ENABLE_GRADLE_PLUGIN) } + return data +} ``` diff --git a/ktorfit-compiler-plugin/Readme.md b/ktorfit-compiler-plugin/Readme.md index f66f2d3de..b3aedb4a2 100644 --- a/ktorfit-compiler-plugin/Readme.md +++ b/ktorfit-compiler-plugin/Readme.md @@ -12,5 +12,5 @@ val api = jvmKtorfit.create() will be transformed to: ```kotlin -val api = jvmKtorfit.create(_ExampleApiImpl()) +val api = jvmKtorfit.create(_ExampleApiImpl(jvmKtorfit)) ``` diff --git a/ktorfit-compiler-plugin/src/main/java/de/jensklingenberg/ktorfit/CreateFuncTransformer.kt b/ktorfit-compiler-plugin/src/main/java/de/jensklingenberg/ktorfit/CreateFuncTransformer.kt index cba537eba..e69e4be84 100644 --- a/ktorfit-compiler-plugin/src/main/java/de/jensklingenberg/ktorfit/CreateFuncTransformer.kt +++ b/ktorfit-compiler-plugin/src/main/java/de/jensklingenberg/ktorfit/CreateFuncTransformer.kt @@ -83,9 +83,11 @@ class CreateFuncTransformer( symbol = newConstructor, 0, 0, - 0, + 1, null - ) + ).apply { + this.putValueArgument(0, expression.dispatchReceiver) + } //Set _ExampleApiImpl() as argument for create() irCall.putValueArgument(0, newCall) diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/ClassData.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/ClassData.kt index 0e86b75ca..65f27fca3 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/ClassData.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/ClassData.kt @@ -36,8 +36,12 @@ const val WILDCARDIMPORT = "WILDCARDIMPORT" */ fun ClassData.getImplClassFileSource(resolver: Resolver): String { val classData = this - val optinAnnotation = AnnotationSpec.builder(ClassName("kotlin", "OptIn")) - .addMember("InternalKtorfitApi::class") + val optinAnnotation = AnnotationSpec + .builder(ClassName("kotlin", "OptIn")) + .addMember( + "%T::class", + internalApi + ) .build() val suppressAnnotation = AnnotationSpec.builder(ClassName("kotlin", "Suppress")) @@ -72,29 +76,35 @@ fun ClassData.getImplClassFileSource(resolver: Resolver): String { val implClassName = "_${classData.name}Impl" - val clientProperty = PropertySpec + val ktorfitProperty = PropertySpec .builder( - clientClass.objectName, - TypeVariableName(clientClass.name), - listOf(KModifier.OVERRIDE, KModifier.LATEINIT) + name = ktorfitClass.objectName, + type = ktorfitClass.toClassName() ) - .mutable(true) + .initializer(ktorfitClass.objectName) + .mutable(false) + .addModifiers(KModifier.PRIVATE) .build() + val converterProperty = PropertySpec.builder("_converter", internalKtorfitClientType) + .initializer("%T(${ktorfitClass.objectName})", internalKtorfitClientType) + .build() val implClassSpec = TypeSpec.classBuilder(implClassName) + .primaryConstructor( + FunSpec.constructorBuilder() + .addParameter(ktorfitClass.objectName, ktorfitClass.toClassName()) + .build() + ) .addAnnotation( optinAnnotation ) - .addModifiers(classData.modifiers) .addSuperinterface(ClassName(classData.packageName, classData.name)) - .addSuperinterface(ktorfitServiceClassName) .addKtorfitSuperInterface(classData.superClasses) .addFunctions(classData.functions.map { it.toFunSpec(resolver) }) - .addProperty( - clientProperty - ) + .addProperty(converterProperty) + .addProperty(ktorfitProperty) .addProperties(properties) .build() @@ -117,8 +127,8 @@ private fun getCreateExtensionFunctionSpec( ): FunSpec { return FunSpec.builder("create${classData.name}") .addModifiers(classData.modifiers) - .addStatement("return this.create(_${classData.name}Impl())") - .receiver(TypeVariableName(ktorfitClass.name)) + .addStatement("return this.create(_${classData.name}Impl(this))") + .receiver(ktorfitClass.toClassName()) .returns(TypeVariableName(classData.name)) .build() } @@ -222,7 +232,12 @@ fun TypeSpec.Builder.addKtorfitSuperInterface(superClasses: List(${typeDataClass.objectName},${extDataClass.objectName})$nullableText", - ktorfitClientClass.objectName, + "return %L.%L<${returnTypeName}, ${innerReturnType}>(${typeDataClass.objectName},${extDataClass.objectName})%L", + "_converter", if (this.isSuspend) { "suspendRequest" } else { "request" + }, + if (this.returnType.isNullable) { + "" + } else { + "!!" } ) .build() diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitClass.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitClass.kt index e9c9794d5..50f63e916 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitClass.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitClass.kt @@ -4,11 +4,11 @@ import com.squareup.kotlinpoet.ClassName data class KtorfitClass(val name: String, val packageName: String, val objectName: String) -val ktorfitClientClass = KtorfitClass("KtorfitClient", "de.jensklingenberg.ktorfit.internal", "ktorfitClient") -val clientClass = KtorfitClass("Client", "de.jensklingenberg.ktorfit.internal", "ktorfitClient") -val ktorfitClass = KtorfitClass("Ktorfit", "de.jensklingenberg.ktorfit", "") +val ktorfitClass = KtorfitClass("Ktorfit", "de.jensklingenberg.ktorfit", "_ktorfit") val typeDataClass = KtorfitClass("TypeData", "de.jensklingenberg.ktorfit.internal", "_typeData") -val ktorfitServiceClassName = ClassName("de.jensklingenberg.ktorfit.internal", "KtorfitService") -val extDataClass = KtorfitClass("", "", "_ext") +val extDataClass = KtorfitClass("HttpRequestBuilder.() -> Unit", "", "_ext") val formParameters = KtorfitClass("", "", "__formParameters") +val internalApi = ClassName("de.jensklingenberg.ktorfit.internal", "InternalKtorfitApi") +val internalKtorfitClientType = ClassName("de.jensklingenberg.ktorfit.internal", "KtorfitConverterHelper") +fun KtorfitClass.toClassName() = ClassName(packageName, name) \ No newline at end of file diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/UrlCodeGeneration.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/UrlCodeGeneration.kt index aec1821c4..ef1ed6e34 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/UrlCodeGeneration.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/UrlCodeGeneration.kt @@ -4,7 +4,7 @@ import de.jensklingenberg.ktorfit.model.ParameterData import de.jensklingenberg.ktorfit.model.annotations.HttpMethodAnnotation import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.Path import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.Url -import de.jensklingenberg.ktorfit.model.ktorfitClientClass +import de.jensklingenberg.ktorfit.model.ktorfitClass fun getUrlCode(params: List, methodAnnotation: HttpMethodAnnotation, queryCode: String): String { @@ -19,8 +19,8 @@ fun getUrlCode(params: List, methodAnnotation: HttpMethodAnnotati "" } else { params.firstOrNull { it.hasAnnotation() }?.let { parameterData -> - "(${ktorfitClientClass.objectName}.baseUrl.takeIf{ !${parameterData.name}.startsWith(\"http\")} ?: \"\") + " - } ?: "${ktorfitClientClass.objectName}.baseUrl + " + "(${ktorfitClass.objectName}.baseUrl.takeIf{ !${parameterData.name}.startsWith(\"http\")} ?: \"\") + " + } ?: "${ktorfitClass.objectName}.baseUrl + " } params.filter { it.hasAnnotation() }.forEach { parameterData -> diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/typeData/RequestConverterText.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/typeData/RequestConverterText.kt index e9eb34a77..54ffd9a85 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/typeData/RequestConverterText.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/typeData/RequestConverterText.kt @@ -4,7 +4,7 @@ import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.ksp.toClassName import de.jensklingenberg.ktorfit.model.ParameterData import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.RequestType -import de.jensklingenberg.ktorfit.model.ktorfitClientClass +import de.jensklingenberg.ktorfit.model.ktorfitClass fun FunSpec.Builder.addRequestConverterText(parameterDataList: List) = apply { if (parameterDataList.any { it.hasAnnotation() }) { @@ -16,7 +16,7 @@ fun FunSpec.Builder.addRequestConverterText(parameterDataList: List Unit = { method = HttpMethod.parse("GET2") url{ - takeFrom(ktorfitClient.baseUrl + "user") + takeFrom(_ktorfit.baseUrl + "user") } setBody(body) }""" diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/QueryAnnotationsTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/QueryAnnotationsTest.kt index 5bbb579da..bd165cb3f 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/QueryAnnotationsTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/QueryAnnotationsTest.kt @@ -30,7 +30,7 @@ interface TestService { ) val expectedQueriesArgumentText = "url{\n" + - " takeFrom(ktorfitClient.baseUrl + \"posts\")\n" + + " takeFrom(_ktorfit.baseUrl + \"posts\")\n" + " testQuery?.let{ parameter(\"name\", \"\$it\") }\n" + " testQuery2?.let{ encodedParameters.append(\"testQuery2\", \"\$it\") }\n" + " }" @@ -66,7 +66,7 @@ interface TestService { ) val expectedQueriesArgumentText = "url{\n" + - " takeFrom(ktorfitClient.baseUrl + \"posts\")\n" + + " takeFrom(_ktorfit.baseUrl + \"posts\")\n" + " testQuery2?.filterNotNull()?.forEach { encodedParameters.append(\"user\", \"\$it\") }\n" + " }" @@ -100,7 +100,7 @@ interface TestService { ) val expectedQueriesArgumentText = "url{\n" + - " takeFrom(ktorfitClient.baseUrl + \"posts\")\n" + + " takeFrom(_ktorfit.baseUrl + \"posts\")\n" + " parameters.appendAll(\"\$testQueryName\", emptyList())\n" + " parameters.appendAll(\"\$testQueryName2\", emptyList())\n" + " }" @@ -138,7 +138,7 @@ interface TestService { val expectedQueriesArgumentText = "url{\n" + - " takeFrom(ktorfitClient.baseUrl + \"posts\")\n" + + " takeFrom(_ktorfit.baseUrl + \"posts\")\n" + " testQueryMap?.forEach { entry -> entry.value?.let{ parameter(entry.key, \"\${entry.value}\") }\n" + " }\n" + " testQueryMap2?.forEach { entry -> entry.value?.let{ encodedParameters.append(entry.key,\n" + @@ -178,7 +178,7 @@ fun example(@Query("name") testQuery: String, @QueryName testQueryName: String, val expectedQueriesArgumentText = "url{\n" + - " takeFrom(ktorfitClient.baseUrl + \"posts\")\n" + + " takeFrom(_ktorfit.baseUrl + \"posts\")\n" + " testQuery?.let{ parameter(\"name\", \"\$it\") }\n" + " parameters.appendAll(\"\$testQueryName\", emptyList())\n" + " name?.forEach { entry -> entry.value?.let{ encodedParameters.append(entry.key,\n" + diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestConverterTextKtTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestConverterTextKtTest.kt index ea08a5577..9c9014363 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestConverterTextKtTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestConverterTextKtTest.kt @@ -19,7 +19,7 @@ class RequestConverterTextKtTest { @Test fun generateCorrectFunction() { val expected = """public fun TestFunction() { - val test1: com.example.Test = ktorfitClient.convertParameterType(test1,test1::class,com.example.Test::class) + val test1: com.example.Test = _converter.convertParameterType(test1,test1::class,com.example.Test::class) } """ diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestTypeTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestTypeTest.kt index 87c967cde..069b79353 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestTypeTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestTypeTest.kt @@ -25,7 +25,7 @@ interface TestService { """ ) - val expectedFunctionSource = """val postId: Int = ktorfitClient.convertParameterType(postId,postId::class,Int::class)""" + val expectedFunctionSource = """val postId: Int = _converter.convertParameterType(postId,postId::class,Int::class)""" val compilation = getCompilation(listOf(source)) val result = compilation.compile() diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/ReturnTypeDataTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/ReturnTypeDataTest.kt index 8969bdd72..24718d414 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/ReturnTypeDataTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/ReturnTypeDataTest.kt @@ -32,7 +32,7 @@ interface TestService { """val _ext: HttpRequestBuilder.() -> Unit = { method = HttpMethod.parse("POST") url{ - takeFrom(ktorfitClient.baseUrl + "user") + takeFrom(_ktorfit.baseUrl + "user") } setBody(id) }""" diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/StreamingAnnotationTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/StreamingAnnotationTest.kt index b4eea851e..dc5f629ca 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/StreamingAnnotationTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/StreamingAnnotationTest.kt @@ -39,7 +39,7 @@ interface TestService { ) - val expectedFunctionText = """return ktorfitClient.suspendRequest(_typeData,_ext)!!""" + val expectedFunctionText = """return _converter.suspendRequest(_typeData,_ext)!!""" val compilation = getCompilation(listOf(httpStatement, source)) val result = compilation.compile() diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/UrlTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/UrlTest.kt index 812196621..c7e227b2a 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/UrlTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/UrlTest.kt @@ -14,7 +14,7 @@ class UrlTest { @Test fun testFunctionWithGET() { val expectedFunctionSource = """url{ - takeFrom(ktorfitClient.baseUrl + "user") + takeFrom(_ktorfit.baseUrl + "user") }""" val source = SourceFile.kotlin( @@ -63,7 +63,7 @@ interface TestService { val expectedFunctionText = """url{ - takeFrom(ktorfitClient.baseUrl + "user/$\{"$\userId".encodeURLPath()}") + takeFrom(_ktorfit.baseUrl + "user/$\{"$\userId".encodeURLPath()}") } """.replace("$\\", "$") val compilation = getCompilation(listOf(source)) @@ -102,7 +102,7 @@ interface TestService { val expectedFunctionText = """url{ - takeFrom(ktorfitClient.baseUrl + "user/$\{"$\userId".encodeURLPath()}") + takeFrom(_ktorfit.baseUrl + "user/$\{"$\userId".encodeURLPath()}") } """.replace("$\\", "$") val compilation = getCompilation(listOf(source)) @@ -124,7 +124,7 @@ interface TestService { @Test fun testFunctionWithGETAndUrlAnno() { val expectedFunctionSource = """url{ - takeFrom((ktorfitClient.baseUrl.takeIf{ !url.startsWith("http")} ?: "") + "$\{url}") + takeFrom((_ktorfit.baseUrl.takeIf{ !url.startsWith("http")} ?: "") + "$\{url}") }""".replace("$\\", "$") @@ -220,7 +220,7 @@ interface TestService { ) val expectedFunctionText = """url{ - takeFrom(ktorfitClient.baseUrl + "user/$\{"$\id"}") + takeFrom(_ktorfit.baseUrl + "user/$\{"$\id"}") }""".replace("$\\", "$") val compilation = getCompilation(listOf(source)) diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/UrlArgumentTextKtTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/UrlArgumentTextKtTest.kt index 1bdd4a31f..6c89a369b 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/UrlArgumentTextKtTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/UrlArgumentTextKtTest.kt @@ -17,7 +17,7 @@ class UrlArgumentTextKtTest { val params = listOf(parameterData) val text = getUrlCode(params, HttpMethodAnnotation("posts", HttpMethod.GET), "") val expected = "url{\n" + - "takeFrom(ktorfitClient.baseUrl + \"posts\")\n" + + "takeFrom(_ktorfit.baseUrl + \"posts\")\n" + "}".trimMargin() assertEquals( expected, text @@ -33,7 +33,7 @@ class UrlArgumentTextKtTest { val text = getUrlCode(params, HttpMethodAnnotation("posts", HttpMethod.GET), "") assertEquals( "url{\n" + - "takeFrom((ktorfitClient.baseUrl.takeIf{ !test1.startsWith(\"http\")} ?: \"\") + \"posts\")\n" + + "takeFrom((_ktorfit.baseUrl.takeIf{ !test1.startsWith(\"http\")} ?: \"\") + \"posts\")\n" + "}", text ) @@ -48,7 +48,7 @@ class UrlArgumentTextKtTest { val text = getUrlCode(params, HttpMethodAnnotation("", HttpMethod.GET), "") val expected = String.format( "url{\n" + - "takeFrom((ktorfitClient.baseUrl.takeIf{ !test1.startsWith(\"http\")} ?: \"\") + \"%s{test1}\")\n" + + "takeFrom((_ktorfit.baseUrl.takeIf{ !test1.startsWith(\"http\")} ?: \"\") + \"%s{test1}\")\n" + "}", "$" ) @@ -60,7 +60,7 @@ class UrlArgumentTextKtTest { val parameterData = ParameterData("test1", ReturnTypeData("String", "kotlin.String", null)) val params = listOf(parameterData) val text = getUrlCode(params, HttpMethodAnnotation("", HttpMethod.GET), "") - assertEquals("url{\ntakeFrom(ktorfitClient.baseUrl + \"\")\n}", text) + assertEquals("url{\ntakeFrom(_ktorfit.baseUrl + \"\")\n}", text) } @Test @@ -72,7 +72,7 @@ class UrlArgumentTextKtTest { val text = getUrlCode(params, HttpMethodAnnotation("user/{testValue}", HttpMethod.GET), "") assertEquals( """url{ -takeFrom(ktorfitClient.baseUrl + "user/$/{"$/test1".encodeURLPath()}") +takeFrom(_ktorfit.baseUrl + "user/$/{"$/test1".encodeURLPath()}") }""".replace("$/", "$"), text ) diff --git a/ktorfit-lib-core/api/android/ktorfit-lib-core.api b/ktorfit-lib-core/api/android/ktorfit-lib-core.api index f31e3dfb8..e6f8db5ca 100644 --- a/ktorfit-lib-core/api/android/ktorfit-lib-core.api +++ b/ktorfit-lib-core/api/android/ktorfit-lib-core.api @@ -1,7 +1,7 @@ public final class de/jensklingenberg/ktorfit/Ktorfit { public synthetic fun (Ljava/lang/String;Lio/ktor/client/HttpClient;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun create (Lde/jensklingenberg/ktorfit/internal/KtorfitService;)Ljava/lang/Object; - public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/KtorfitService;ILjava/lang/Object;)Ljava/lang/Object; + public final fun create (Ljava/lang/Object;)Ljava/lang/Object; + public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Ljava/lang/Object;ILjava/lang/Object;)Ljava/lang/Object; public final fun getBaseUrl ()Ljava/lang/String; public final fun getHttpClient ()Lio/ktor/client/HttpClient; public final fun getResponseConverters ()Ljava/util/Set; @@ -28,8 +28,6 @@ public final class de/jensklingenberg/ktorfit/Ktorfit$Builder { } public final class de/jensklingenberg/ktorfit/KtorfitKt { - public static final fun create (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/KtorfitService;)Ljava/lang/Object; - public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/KtorfitService;ILjava/lang/Object;)Ljava/lang/Object; public static final fun ktorfit (Lkotlin/jvm/functions/Function1;)Lde/jensklingenberg/ktorfit/Ktorfit; public static final fun ktorfitBuilder (Lkotlin/jvm/functions/Function1;)Lde/jensklingenberg/ktorfit/Ktorfit$Builder; } @@ -134,24 +132,14 @@ public abstract interface class de/jensklingenberg/ktorfit/converter/request/Res public abstract fun wrapResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;)Ljava/lang/Object; } -public abstract interface class de/jensklingenberg/ktorfit/internal/Client { - public abstract fun convertParameterType (Ljava/lang/Object;Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Ljava/lang/Object; - public abstract fun getBaseUrl ()Ljava/lang/String; - public abstract fun request (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun suspendRequest (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - public abstract interface annotation class de/jensklingenberg/ktorfit/internal/InternalKtorfitApi : java/lang/annotation/Annotation { } -public abstract interface class de/jensklingenberg/ktorfit/internal/KtorfitService { - public abstract fun getKtorfitClient ()Lde/jensklingenberg/ktorfit/internal/Client; - public abstract fun setClient (Lde/jensklingenberg/ktorfit/internal/Client;)V - public abstract fun setKtorfitClient (Lde/jensklingenberg/ktorfit/internal/Client;)V -} - -public final class de/jensklingenberg/ktorfit/internal/KtorfitService$DefaultImpls { - public static fun setClient (Lde/jensklingenberg/ktorfit/internal/KtorfitService;Lde/jensklingenberg/ktorfit/internal/Client;)V +public final class de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper { + public fun (Lde/jensklingenberg/ktorfit/Ktorfit;)V + public final fun convertParameterType (Ljava/lang/Object;Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Ljava/lang/Object; + public final fun request (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public final fun suspendRequest (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public final class de/jensklingenberg/ktorfit/internal/TypeData { diff --git a/ktorfit-lib-core/api/jvm/ktorfit-lib-core.api b/ktorfit-lib-core/api/jvm/ktorfit-lib-core.api index f31e3dfb8..e6f8db5ca 100644 --- a/ktorfit-lib-core/api/jvm/ktorfit-lib-core.api +++ b/ktorfit-lib-core/api/jvm/ktorfit-lib-core.api @@ -1,7 +1,7 @@ public final class de/jensklingenberg/ktorfit/Ktorfit { public synthetic fun (Ljava/lang/String;Lio/ktor/client/HttpClient;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun create (Lde/jensklingenberg/ktorfit/internal/KtorfitService;)Ljava/lang/Object; - public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/KtorfitService;ILjava/lang/Object;)Ljava/lang/Object; + public final fun create (Ljava/lang/Object;)Ljava/lang/Object; + public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Ljava/lang/Object;ILjava/lang/Object;)Ljava/lang/Object; public final fun getBaseUrl ()Ljava/lang/String; public final fun getHttpClient ()Lio/ktor/client/HttpClient; public final fun getResponseConverters ()Ljava/util/Set; @@ -28,8 +28,6 @@ public final class de/jensklingenberg/ktorfit/Ktorfit$Builder { } public final class de/jensklingenberg/ktorfit/KtorfitKt { - public static final fun create (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/KtorfitService;)Ljava/lang/Object; - public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/KtorfitService;ILjava/lang/Object;)Ljava/lang/Object; public static final fun ktorfit (Lkotlin/jvm/functions/Function1;)Lde/jensklingenberg/ktorfit/Ktorfit; public static final fun ktorfitBuilder (Lkotlin/jvm/functions/Function1;)Lde/jensklingenberg/ktorfit/Ktorfit$Builder; } @@ -134,24 +132,14 @@ public abstract interface class de/jensklingenberg/ktorfit/converter/request/Res public abstract fun wrapResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;)Ljava/lang/Object; } -public abstract interface class de/jensklingenberg/ktorfit/internal/Client { - public abstract fun convertParameterType (Ljava/lang/Object;Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Ljava/lang/Object; - public abstract fun getBaseUrl ()Ljava/lang/String; - public abstract fun request (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun suspendRequest (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - public abstract interface annotation class de/jensklingenberg/ktorfit/internal/InternalKtorfitApi : java/lang/annotation/Annotation { } -public abstract interface class de/jensklingenberg/ktorfit/internal/KtorfitService { - public abstract fun getKtorfitClient ()Lde/jensklingenberg/ktorfit/internal/Client; - public abstract fun setClient (Lde/jensklingenberg/ktorfit/internal/Client;)V - public abstract fun setKtorfitClient (Lde/jensklingenberg/ktorfit/internal/Client;)V -} - -public final class de/jensklingenberg/ktorfit/internal/KtorfitService$DefaultImpls { - public static fun setClient (Lde/jensklingenberg/ktorfit/internal/KtorfitService;Lde/jensklingenberg/ktorfit/internal/Client;)V +public final class de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper { + public fun (Lde/jensklingenberg/ktorfit/Ktorfit;)V + public final fun convertParameterType (Ljava/lang/Object;Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Ljava/lang/Object; + public final fun request (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public final fun suspendRequest (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public final class de/jensklingenberg/ktorfit/internal/TypeData { diff --git a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Ktorfit.kt b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Ktorfit.kt index 6614b5b45..950eae1d3 100644 --- a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Ktorfit.kt +++ b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Ktorfit.kt @@ -81,15 +81,14 @@ public class Ktorfit private constructor( /** * This will return an implementation of [T] if [T] is an interface * with Ktorfit annotations. - * @param ktorfitService Please keep the default parameter, it will be replaced + * @param data Please keep the default parameter, it will be replaced * by the compiler plugin */ - public fun create(ktorfitService: KtorfitService = DefaultKtorfitService()): T { - if (ktorfitService is DefaultKtorfitService) { + public fun create(data: T? = null): T { + if (data == null) { throw IllegalArgumentException(ENABLE_GRADLE_PLUGIN) } - ktorfitService.setClient(KtorfitClient(this)) - return ktorfitService as T + return data } @@ -232,15 +231,4 @@ public fun ktorfit(builder: Ktorfit.Builder.() -> Unit): Ktorfit = Ktorfit.Build */ public fun ktorfitBuilder(builder: Ktorfit.Builder.() -> Unit): Ktorfit.Builder = Ktorfit.Builder().apply(builder) -@OptIn(InternalKtorfitApi::class) -@Deprecated("Use the non-Extension function") -/** - * This will return an implementation of [T] if [T] is an interface - * with Ktorfit annotations. - * @param ktorfitService Please keep the default parameter, it will be replaced - * by the compiler plugin - */ -public fun Ktorfit.create(ktorfitService: KtorfitService = DefaultKtorfitService()): T { - return this.create(ktorfitService) -} diff --git a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/Client.kt b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/Client.kt deleted file mode 100644 index a3c540ae6..000000000 --- a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/Client.kt +++ /dev/null @@ -1,36 +0,0 @@ -package de.jensklingenberg.ktorfit.internal - -import io.ktor.client.request.* -import kotlin.reflect.KClass - -@InternalKtorfitApi -public interface Client { - - /** - * This will handle all requests for functions without suspend modifier - */ - public fun request( - returnTypeData: TypeData, - requestBuilder: HttpRequestBuilder.() -> Unit - ): ReturnType? - - /** - * This will handle all requests for functions with suspend modifier - * Used by generated Code - */ - public suspend fun suspendRequest( - typeData: TypeData, - requestBuilder: HttpRequestBuilder.() -> Unit - ): ReturnType? - - /** - * Convert [data] of type [parameterType] to [requestType] - * @return converted [data] - */ - public fun convertParameterType(data: Any, parameterType: KClass<*>, requestType: KClass): T - - /** - * Set baseUrl of the client - */ - public val baseUrl: String -} \ No newline at end of file diff --git a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/HandleDeprecatedConverters.kt b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/HandleDeprecatedConverters.kt index 618f7ef00..7e578ab5c 100644 --- a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/HandleDeprecatedConverters.kt +++ b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/HandleDeprecatedConverters.kt @@ -7,7 +7,7 @@ import io.ktor.client.statement.* import io.ktor.util.reflect.* @OptIn(InternalKtorfitApi::class) -internal fun KtorfitClient.handleDeprecatedResponseConverters( +internal fun KtorfitConverterHelper.handleDeprecatedResponseConverters( returnTypeData: TypeData, ktorfit: Ktorfit, requestBuilder: HttpRequestBuilder.() -> Unit diff --git a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitClient.kt b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper.kt similarity index 77% rename from ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitClient.kt rename to ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper.kt index a8b395f24..bb8d75d76 100644 --- a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitClient.kt +++ b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper.kt @@ -3,23 +3,28 @@ package de.jensklingenberg.ktorfit.internal import de.jensklingenberg.ktorfit.Ktorfit import de.jensklingenberg.ktorfit.converter.KtorfitResult import de.jensklingenberg.ktorfit.converter.builtin.DefaultSuspendResponseConverterFactory -import io.ktor.client.* -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.util.reflect.* +import io.ktor.client.HttpClient +import io.ktor.client.request.HttpRequestBuilder +import io.ktor.client.request.prepareRequest +import io.ktor.client.request.request +import io.ktor.client.statement.HttpResponse +import io.ktor.client.statement.HttpStatement +import io.ktor.util.reflect.typeInfo import kotlin.reflect.KClass import kotlin.reflect.cast +/** + * Cant make this internal because it is used by generated code + */ @InternalKtorfitApi -internal class KtorfitClient(private val ktorfit: Ktorfit) : Client { +public class KtorfitConverterHelper(private val ktorfit: Ktorfit) { private val httpClient: HttpClient = ktorfit.httpClient - override val baseUrl: String = ktorfit.baseUrl /** * This will handle all requests for functions without suspend modifier */ - override fun request( + public fun request( returnTypeData: TypeData, requestBuilder: HttpRequestBuilder.() -> Unit ): ReturnType? { @@ -27,7 +32,10 @@ internal class KtorfitClient(private val ktorfit: Ktorfit) : Client { ktorfit.nextResponseConverter(null, returnTypeData)?.let { responseConverter -> return responseConverter.convert { suspendRequest( - TypeData.createTypeData("io.ktor.client.statement.HttpResponse", typeInfo()), + TypeData.createTypeData( + "io.ktor.client.statement.HttpResponse", + typeInfo() + ), requestBuilder )!! } as ReturnType? @@ -36,7 +44,11 @@ internal class KtorfitClient(private val ktorfit: Ktorfit) : Client { /** * Keeping this for compatibility */ - handleDeprecatedResponseConverters(returnTypeData, ktorfit, requestBuilder)?.let { + handleDeprecatedResponseConverters( + returnTypeData, + ktorfit, + requestBuilder + )?.let { return it } @@ -53,7 +65,7 @@ internal class KtorfitClient(private val ktorfit: Ktorfit) : Client { * This will handle all requests for functions with suspend modifier * Used by generated Code */ - override suspend fun suspendRequest( + public suspend fun suspendRequest( typeData: TypeData, requestBuilder: HttpRequestBuilder.() -> Unit ): ReturnType? { @@ -86,7 +98,10 @@ internal class KtorfitClient(private val ktorfit: Ktorfit) : Client { requestBuilder )?.let { return it - } ?: DefaultSuspendResponseConverterFactory().suspendResponseConverter(typeData, ktorfit).let { + } ?: DefaultSuspendResponseConverterFactory().suspendResponseConverter( + typeData, + ktorfit + ).let { val result: KtorfitResult = try { KtorfitResult.Success(httpClient.request { requestBuilder(this) @@ -107,7 +122,11 @@ internal class KtorfitClient(private val ktorfit: Ktorfit) : Client { } } - override fun convertParameterType(data: Any, parameterType: KClass<*>, requestType: KClass): T { + public fun convertParameterType( + data: Any, + parameterType: KClass<*>, + requestType: KClass + ): T { ktorfit.nextRequestParameterConverter(null, parameterType, requestType)?.let { return requestType.cast(it.convert(data)) } diff --git a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitService.kt b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitService.kt deleted file mode 100644 index ff3f9f72e..000000000 --- a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitService.kt +++ /dev/null @@ -1,26 +0,0 @@ -package de.jensklingenberg.ktorfit.internal - -/** - * This will be implemented by classes that - * are generated by Ktorfit-Ksp. - */ -public interface KtorfitService { - public var ktorfitClient: Client - - /** - * Used to set the [ktorfitClient] at runtime - */ - public fun setClient(ktorfitClient: Client) { - this.ktorfitClient = ktorfitClient - } -} - -/** - * This will be used as default parameter for [Ktorfit.create]. - * When this class is used at runtime, it means that the compiler plugin - * did not replace the default parameter with the right class - */ -@OptIn(InternalKtorfitApi::class) -internal class DefaultKtorfitService : KtorfitService { - override lateinit var ktorfitClient: Client -} \ No newline at end of file diff --git a/ktorfit-lib-core/src/commonTest/kotlin/de/jensklingenberg/ktorfit/converter/RequestParameterConverterTest.kt b/ktorfit-lib-core/src/commonTest/kotlin/de/jensklingenberg/ktorfit/converter/RequestParameterConverterTest.kt index 7acbc49d1..45a1345b9 100644 --- a/ktorfit-lib-core/src/commonTest/kotlin/de/jensklingenberg/ktorfit/converter/RequestParameterConverterTest.kt +++ b/ktorfit-lib-core/src/commonTest/kotlin/de/jensklingenberg/ktorfit/converter/RequestParameterConverterTest.kt @@ -3,15 +3,15 @@ package de.jensklingenberg.ktorfit.converter import de.jensklingenberg.ktorfit.Ktorfit import de.jensklingenberg.ktorfit.TestEngine import de.jensklingenberg.ktorfit.TestStringToIntRequestConverter -import de.jensklingenberg.ktorfit.internal.Client -import de.jensklingenberg.ktorfit.internal.KtorfitClient -import io.ktor.client.request.* - +import de.jensklingenberg.ktorfit.internal.InternalKtorfitApi +import de.jensklingenberg.ktorfit.internal.KtorfitConverterHelper +import io.ktor.client.request.HttpRequestData import kotlin.test.Test import kotlin.test.assertEquals class RequestParameterConverterTest { + @OptIn(InternalKtorfitApi::class) @Test fun testRequestConverter() { @@ -23,7 +23,7 @@ class RequestParameterConverterTest { val ktorfit = Ktorfit.Builder().httpClient(engine).baseUrl("http://www.test.de/").requestConverter(TestStringToIntRequestConverter()).build() - val converted = (KtorfitClient(ktorfit) as Client).convertParameterType("4", String::class, Int::class) + val converted = KtorfitConverterHelper(ktorfit).convertParameterType("4", String::class, Int::class) assertEquals(4, converted) } diff --git a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/BodyTest.kt b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/BodyTest.kt index 0efbe6e04..c9625516f 100644 --- a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/BodyTest.kt +++ b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/BodyTest.kt @@ -38,7 +38,7 @@ class BodyTest { .build() runBlocking { - ktorfit.create(_BodyTestApiImpl()).testBody("testBody") + ktorfit.create(_BodyTestApiImpl(ktorfit)).testBody("testBody") } } catch (ex: Exception) { diff --git a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/BuilderTest.kt b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/BuilderTest.kt index 5a7b19d83..d6f128a88 100644 --- a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/BuilderTest.kt +++ b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/BuilderTest.kt @@ -71,7 +71,7 @@ class BuilderTest { val ktorfit = Ktorfit.Builder().baseUrl(testBaseUrl, false).httpClient(HttpClient(engine)).build() runBlocking { - ktorfit.create(_BuilderTestApiImpl()).checkIfBaseUrlIsSetWhenUrlCheckIsDisabled() + ktorfit.create(_BuilderTestApiImpl(ktorfit)).checkIfBaseUrlIsSetWhenUrlCheckIsDisabled() } } } \ No newline at end of file diff --git a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterFactoryTest.kt b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterFactoryTest.kt index 74d45ac20..a2b976d75 100644 --- a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterFactoryTest.kt +++ b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterFactoryTest.kt @@ -61,7 +61,7 @@ class ConverterFactoryTest { .build() runBlocking { - ktorfit.create(_ConverterFactoryTestApiImpl()).suspendClientException() + ktorfit.create(_ConverterFactoryTestApiImpl(ktorfit)).suspendClientException() } @@ -106,7 +106,7 @@ class ConverterFactoryTest { .build() runBlocking { - ktorfit.create(_ConverterFactoryTestApiImpl()).clientException().collect() + ktorfit.create(_ConverterFactoryTestApiImpl(ktorfit)).clientException().collect() } diff --git a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterTest.kt b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterTest.kt index a275c9833..5b2c4e588 100644 --- a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterTest.kt +++ b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterTest.kt @@ -57,7 +57,7 @@ class ConverterTest { Ktorfit.Builder().httpClient(engine).baseUrl("http://www.jensklingenberg.de/").responseConverter(test) .build() runBlocking { - ktorfit.create(_ConverterTestApiImpl()).clientException().collect() + ktorfit.create(_ConverterTestApiImpl(ktorfit)).clientException().collect() } } catch (exception: Exception) { diff --git a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitClientTest.kt b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitClientTest.kt index 9d5855eed..eca2ce402 100644 --- a/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitClientTest.kt +++ b/ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitClientTest.kt @@ -44,7 +44,7 @@ class ClientTest { val ktorfit = Ktorfit.Builder().baseUrl(testBaseUrl).httpClient(HttpClient(engine)).build() runBlocking { - ktorfit.create(_ClientTestApiImpl()).checkCorrectHttpMethod() + ktorfit.create(_ClientTestApiImpl(ktorfit)).checkCorrectHttpMethod() } } @@ -67,7 +67,7 @@ class ClientTest { val ktorfit = Ktorfit.Builder().baseUrl("http://www.test.de/").httpClient(client).build() runBlocking { - ktorfit.create(_ClientTestApiImpl()).converterMissing() + ktorfit.create(_ClientTestApiImpl(ktorfit)).converterMissing() } } catch (exception: Exception) { @@ -82,7 +82,7 @@ class ClientTest { val ktorfit = Ktorfit.Builder().baseUrl("http://www.test.de/").build() - val converted = (KtorfitClient(ktorfit) as Client).convertParameterType("4", String::class, Int::class) + val converted = KtorfitConverterHelper(ktorfit).convertParameterType("4", String::class, Int::class) assertEquals(4, converted) } catch (ex: Exception) { @@ -107,7 +107,7 @@ class ClientTest { val ktorfit = Ktorfit.Builder().baseUrl("http://www.example1.com/").httpClient(HttpClient(engine)).build() try { runBlocking { - ktorfit.create(_ClientTestApiImpl()).whenUrlValueContainsBaseUrl_ThenRemoveBaseUrl() + ktorfit.create(_ClientTestApiImpl(ktorfit)).whenUrlValueContainsBaseUrl_ThenRemoveBaseUrl() } } catch (ex: Exception) {