diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 72e7a8fc5..ee8c4d410 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,11 @@ and this project orients towards [Semantic Versioning](http://semver.org/spec/v2 Note: This project needs KSP to work and every new Ktorfit with an update of the KSP version is technically a breaking change. But there is no intent to bump the Ktorfit major version for every KSP update. +2.0.0-beta2 - 2024-05-16 +======================================== +- Build with KSP 1.0.20, Kotlin 2.0.0-RC3, Ktor 2.3.11 +- Optimize code generation + 2.0.0-beta1 - 2024-04-28 ======================================== ### Breaking Changes diff --git a/example/AndroidOnlyExample/app/build.gradle.kts b/example/AndroidOnlyExample/app/build.gradle.kts index df33f49e9..304b45175 100644 --- a/example/AndroidOnlyExample/app/build.gradle.kts +++ b/example/AndroidOnlyExample/app/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("org.jetbrains.kotlin.android") id("com.google.devtools.ksp") version "1.9.23-1.0.20" id("org.jetbrains.kotlin.plugin.serialization") version "1.9.23" - id("de.jensklingenberg.ktorfit") version "2.0.0-beta1" + id("de.jensklingenberg.ktorfit") version "2.0.0-beta2-SNAPSHOT" } @@ -51,7 +51,7 @@ tasks.withType().configureEach } } -val ktorfit = "2.0.0-beta1" +val ktorfit = "2.0.0-beta2-SNAPSHOT" val ktor = "2.3.10" val compose_ui_version = "1.5.1" dependencies { @@ -65,8 +65,8 @@ dependencies { implementation("de.jensklingenberg.ktorfit:ktorfit-converters-flow:$ktorfit") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") - implementation("androidx.activity:activity-compose:1.8.0") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0") + implementation("androidx.activity:activity-compose:1.9.0") implementation("androidx.compose.ui:ui:$compose_ui_version") implementation("androidx.compose.ui:ui-tooling-preview:$compose_ui_version") implementation("androidx.compose.material:material:1.5.2") diff --git a/example/AndroidOnlyExample/app/src/main/java/de/jensklingenberg/androidonlyexample/MainActivity.kt b/example/AndroidOnlyExample/app/src/main/java/de/jensklingenberg/androidonlyexample/MainActivity.kt index 3c9696520..beff01dc0 100644 --- a/example/AndroidOnlyExample/app/src/main/java/de/jensklingenberg/androidonlyexample/MainActivity.kt +++ b/example/AndroidOnlyExample/app/src/main/java/de/jensklingenberg/androidonlyexample/MainActivity.kt @@ -35,7 +35,6 @@ val ktorfit = ktorfit { ) } -val api: StarWarsApi = ktorfit.create() class MainActivity : ComponentActivity() { @@ -59,7 +58,7 @@ class MainActivity : ComponentActivity() { } lifecycleScope.launch { - peopleState.value = api.getPerson(1) + peopleState.value = ktorfit.create().getPerson(1) } } } \ No newline at end of file diff --git a/example/MultiplatformExample/build.gradle.kts b/example/MultiplatformExample/build.gradle.kts index 36866adfa..726d3515f 100644 --- a/example/MultiplatformExample/build.gradle.kts +++ b/example/MultiplatformExample/build.gradle.kts @@ -9,9 +9,9 @@ buildscript { } } dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0-RC3") classpath("com.android.tools.build:gradle:7.3.1") - classpath("org.jetbrains.kotlin:kotlin-serialization:1.9.23") + classpath("org.jetbrains.kotlin:kotlin-serialization:2.0.0-RC3") } } diff --git a/example/MultiplatformExample/shared/build.gradle.kts b/example/MultiplatformExample/shared/build.gradle.kts index b39d7a1ad..cbbbe4d7e 100644 --- a/example/MultiplatformExample/shared/build.gradle.kts +++ b/example/MultiplatformExample/shared/build.gradle.kts @@ -2,14 +2,14 @@ plugins { kotlin("multiplatform") kotlin("native.cocoapods") id("com.android.library") - id("com.google.devtools.ksp") version "1.9.23-1.0.20" + id("com.google.devtools.ksp") version "2.0.0-RC3-1.0.20" id("kotlinx-serialization") - id("de.jensklingenberg.ktorfit") version "2.0.0-beta1" + id("de.jensklingenberg.ktorfit") version "2.0.0-beta2-SNAPSHOT" } version = "1.0" val ktorVersion = "2.3.10" -val ktorfitVersion = "2.0.0-beta1" +val ktorfitVersion = "2.0.0-beta2-SNAPSHOT" kotlin { jvmToolchain(8) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 65a0cbd1d..be13c3414 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,17 +2,23 @@ autoService = "1.1.1" autoServiceKsp = "1.10" binaryCompatibilityValidator = "0.13.2" -coroutines = "1.7.3" +coroutines = "1.8.0" detekt = "1.23.6" junit = "4.13.2" kctfork = "0.4.1" -kotlin = "2.0.0-RC1" +kotlin = "2.0.0-RC3" kotlinPoet = "1.16.0" -kspVersion = "2.0.0-RC1-1.0.20" -ktorfit = "2.0.0-beta1" +kspVersion = "2.0.0-RC3-1.0.20" +ktorfit = "2.0.0-beta2-SNAPSHOT" +ktorfitKsp = "2.0.0-beta2-SNAPSHOT" +ktorfitCompiler = "2.0.0-beta2-SNAPSHOT" +ktorfitCallConverter = "2.0.0-beta2-SNAPSHOT" +ktorfitFlowConverter = "2.0.0-beta2-SNAPSHOT" +ktorfitResponseConverter = "2.0.0-beta2-SNAPSHOT" + ktorfitGradlePlugin = "1.14.0" -ktorVersion = "2.3.10" -mockk = "1.13.10" +ktorVersion = "2.3.11" +mockk = "1.13.8" mockito-kotlin = "4.1.0" gradleMavenPublishPlugin = "0.25.3" vannikMavenPublish = "0.25.3" diff --git a/ktorfit-compiler-plugin/build.gradle.kts b/ktorfit-compiler-plugin/build.gradle.kts index f4e52fa41..081149c3a 100644 --- a/ktorfit-compiler-plugin/build.gradle.kts +++ b/ktorfit-compiler-plugin/build.gradle.kts @@ -21,7 +21,7 @@ licensee { } mavenPublishing { - coordinates("de.jensklingenberg.ktorfit", "compiler-plugin", libs.versions.ktorfit.get()) + coordinates("de.jensklingenberg.ktorfit", "compiler-plugin", libs.versions.ktorfitCompiler.get()) publishToMavenCentral() // publishToMavenCentral(SonatypeHost.S01) for publishing through s01.oss.sonatype.org if (enableSigning) { 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..2a117ee0e 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 @@ -69,7 +69,7 @@ class CreateFuncTransformer( val implClassSymbol = pluginContext.referenceClass( ClassId( FqName(packageName), - Name.identifier("_$className" + "Impl") + Name.identifier("_$className" + "Provider") ) ) ?: throw IllegalStateException(ERROR_IMPL_NOT_FOUND(argumentType.originalKotlinType.toString())) diff --git a/ktorfit-compiler-plugin/src/test/kotlin/de/jensklingenberg/ktorfit/FunctionTransformerTest.kt b/ktorfit-compiler-plugin/src/test/kotlin/de/jensklingenberg/ktorfit/FunctionTransformerTest.kt index 9437eb470..76eabcca8 100644 --- a/ktorfit-compiler-plugin/src/test/kotlin/de/jensklingenberg/ktorfit/FunctionTransformerTest.kt +++ b/ktorfit-compiler-plugin/src/test/kotlin/de/jensklingenberg/ktorfit/FunctionTransformerTest.kt @@ -25,14 +25,12 @@ class FunctionTransformerTest { package de.jensklingenberg.ktorfit class Ktorfit(){ - fun create(ktorfitService: KtorfitService? = null): T { + fun create(ktorfitService: ClassProvider? = null): T { return ktorfitService as T } } -interface KtorfitService - -class Default : KtorfitService +interface ClassProvider """ ) @@ -41,11 +39,13 @@ class Default : KtorfitService package com.example.api import de.jensklingenberg.ktorfit.Ktorfit - import de.jensklingenberg.ktorfit.KtorfitService + import de.jensklingenberg.ktorfit.ClassProvider interface TestService - class _TestServiceImpl : TestService, KtorfitService - + class _TestServiceImpl : TestService{ + + } + class _TestServiceProvider : ClassProvider class TestClass{ val api = Ktorfit().create() } @@ -69,11 +69,9 @@ package de.jensklingenberg.ktorfit class Ktorfit() -interface KtorfitService - -class Default : KtorfitService +interface ClassProvider -fun Ktorfit.create(ktorfitService: KtorfitService = Default()): T { +fun Ktorfit.create(ktorfitService: ClassProvider? = null): T { return this.create(ktorfitService) } @@ -84,10 +82,12 @@ fun Ktorfit.create(ktorfitService: KtorfitService = Default()): T { package com.example.api import de.jensklingenberg.ktorfit.Ktorfit import de.jensklingenberg.ktorfit.create - import de.jensklingenberg.ktorfit.KtorfitService + import de.jensklingenberg.ktorfit.ClassProvider interface TestService - class _TestServiceImpl : TestService, KtorfitService + class _TestServiceImpl : TestService{ + companion object : ClassProvider + } class TestClass{ diff --git a/ktorfit-converters/call/build.gradle.kts b/ktorfit-converters/call/build.gradle.kts index bafda2787..41836b60c 100644 --- a/ktorfit-converters/call/build.gradle.kts +++ b/ktorfit-converters/call/build.gradle.kts @@ -24,7 +24,7 @@ mavenPublishing { coordinates( "de.jensklingenberg.ktorfit", "ktorfit-converters-call", - libs.versions.ktorfit.get() + libs.versions.ktorfitCallConverter.get() ) publishToMavenCentral() // publishToMavenCentral(SonatypeHost.S01) for publishing through s01.oss.sonatype.org diff --git a/ktorfit-converters/flow/build.gradle.kts b/ktorfit-converters/flow/build.gradle.kts index e28524418..d17d0bf12 100644 --- a/ktorfit-converters/flow/build.gradle.kts +++ b/ktorfit-converters/flow/build.gradle.kts @@ -25,7 +25,7 @@ mavenPublishing { coordinates( "de.jensklingenberg.ktorfit", "ktorfit-converters-flow", - libs.versions.ktorfit.get() + libs.versions.ktorfitFlowConverter.get() ) publishToMavenCentral() // publishToMavenCentral(SonatypeHost.S01) for publishing through s01.oss.sonatype.org diff --git a/ktorfit-converters/response/build.gradle.kts b/ktorfit-converters/response/build.gradle.kts index 45302b51a..39ca19ac9 100644 --- a/ktorfit-converters/response/build.gradle.kts +++ b/ktorfit-converters/response/build.gradle.kts @@ -25,7 +25,7 @@ mavenPublishing { coordinates( "de.jensklingenberg.ktorfit", "ktorfit-converters-response", - libs.versions.ktorfit.get() + libs.versions.ktorfitResponseConverter.get() ) publishToMavenCentral() // publishToMavenCentral(SonatypeHost.S01) for publishing through s01.oss.sonatype.org diff --git a/ktorfit-gradle-plugin/build.gradle.kts b/ktorfit-gradle-plugin/build.gradle.kts index ba1bd0609..72c8ad9fb 100644 --- a/ktorfit-gradle-plugin/build.gradle.kts +++ b/ktorfit-gradle-plugin/build.gradle.kts @@ -59,7 +59,7 @@ mavenPublishing { coordinates( "de.jensklingenberg.ktorfit", "ktorfit-gradle-plugin", - libs.versions.ktorfit.get() + libs.versions.ktorfitCompiler.get() ) publishToMavenCentral() // publishToMavenCentral(SonatypeHost.S01) for publishing through s01.oss.sonatype.org diff --git a/ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitCompilerSubPlugin.kt b/ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitCompilerSubPlugin.kt index 4bfadf890..060461dcd 100644 --- a/ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitCompilerSubPlugin.kt +++ b/ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitCompilerSubPlugin.kt @@ -47,7 +47,7 @@ internal class KtorfitCompilerSubPlugin : KotlinCompilerPluginSupportPlugin { return SubpluginArtifact( groupId = SERIALIZATION_GROUP_NAME, artifactId = ARTIFACT_NAME, - version = "2.0.0-beta1" // remember to bump this version before any release! + version = "2.0.0-beta2-SNAPSHOT" // remember to bump this version before any release! ) } } diff --git a/ktorfit-ksp/build.gradle.kts b/ktorfit-ksp/build.gradle.kts index 7caa33995..5b08b0a6f 100644 --- a/ktorfit-ksp/build.gradle.kts +++ b/ktorfit-ksp/build.gradle.kts @@ -27,7 +27,11 @@ tasks.withType { } mavenPublishing { - coordinates("de.jensklingenberg.ktorfit", "ktorfit-ksp", libs.versions.ktorfit.get()) + coordinates( + "de.jensklingenberg.ktorfit", + "ktorfit-ksp", + libs.versions.ktorfitKsp.get() + ) publishToMavenCentral() // publishToMavenCentral(SonatypeHost.S01) for publishing through s01.oss.sonatype.org if (enableSigning) { 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 e76576b68..f51ff66ff 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 @@ -3,21 +3,16 @@ package de.jensklingenberg.ktorfit.model import com.google.devtools.ksp.getDeclaredFunctions import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver -import com.google.devtools.ksp.symbol.ClassKind -import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.KSFile -import com.google.devtools.ksp.symbol.KSPropertyDeclaration -import com.google.devtools.ksp.symbol.KSTypeReference +import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.ksp.toKModifier import com.squareup.kotlinpoet.ksp.toTypeName import de.jensklingenberg.ktorfit.KtorfitOptions import de.jensklingenberg.ktorfit.model.KtorfitError.Companion.PROPERTIES_NOT_SUPPORTED import de.jensklingenberg.ktorfit.model.annotations.FormUrlEncoded import de.jensklingenberg.ktorfit.model.annotations.Multipart -import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.Field -import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.Part -import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.RequestType +import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.* import de.jensklingenberg.ktorfit.utils.addImports /** @@ -80,22 +75,44 @@ fun ClassData.getImplClassFileSource(resolver: Resolver, ktorfitOptions: Ktorfit val implClassName = "_${classData.name}Impl" - val converterProperty = + val helperProperty = PropertySpec.builder(converterHelper.objectName, converterHelper.toClassName()) - .addModifiers(KModifier.LATEINIT, KModifier.OVERRIDE) - .mutable(true) + .initializer("${converterHelper.name}(${ktorfitClass.objectName})") + .addModifiers(KModifier.PRIVATE) .build() - val implClassSpec = TypeSpec.classBuilder(implClassName) + val companion = TypeSpec.classBuilder("_${classData.name}Provider") + .addModifiers(classData.modifiers) + .addSuperinterface( + exampleInterface.toClassName().parameterizedBy(ClassName(classData.packageName, classData.name)) + ) + .addFunction( + FunSpec.builder("create") + .returns(ClassName(classData.packageName, classData.name)) + .addStatement("return _${classData.name}Impl(${ktorfitClass.objectName})") + .addModifiers(KModifier.OVERRIDE) + .addParameter(ktorfitClass.objectName, ktorfitClass.toClassName()) + .build() + ) + .build() - .addAnnotation( - optinAnnotation + val implClassSpec = TypeSpec.classBuilder(implClassName) + .primaryConstructor( + FunSpec.constructorBuilder() + .addParameter(ktorfitClass.objectName, ktorfitClass.toClassName()) + .build() + ) + .addProperty( + PropertySpec.builder(ktorfitClass.objectName, ktorfitClass.toClassName()) + .initializer(ktorfitClass.objectName) + .addModifiers(KModifier.PRIVATE) + .build() ) + .addAnnotation(optinAnnotation) .addModifiers(classData.modifiers) .addSuperinterface(ClassName(classData.packageName, classData.name)) - .addSuperinterface(ktorfitInterface.toClassName()) .addKtorfitSuperInterface(classData.superClasses) - .addProperties(listOf(converterProperty) + properties) + .addProperties(listOf(helperProperty) + properties) .addFunctions(classData.functions.map { it.toFunSpec(resolver, ktorfitOptions.setQualifiedType) }) .build() @@ -104,6 +121,7 @@ fun ClassData.getImplClassFileSource(resolver: Resolver, ktorfitOptions: Ktorfit .addFileComment("Generated by Ktorfit") .addImports(classData.imports) .addType(implClassSpec) + .addType(companion) .addFunction(createExtensionFunctionSpec) .build() .toString() @@ -118,7 +136,7 @@ private fun getCreateExtensionFunctionSpec( val functionName = "create${classData.name}" return FunSpec.builder(functionName) .addModifiers(classData.modifiers) - .addStatement("return this.create(_${classData.name}Impl().apply { ${converterHelper.objectName}= ${converterHelper.name}(this@$functionName) })") + .addStatement("return _${classData.name}Impl(this)") .receiver(ktorfitClass.toClassName()) .returns(ClassName(classData.packageName, classData.name)) .build() @@ -233,7 +251,7 @@ private fun TypeSpec.Builder.addKtorfitSuperInterface(superClasses: List Unit", "", "_ext") val formParameters = KtorfitClass("", "", "__formParameters") -val converterHelper = KtorfitClass("KtorfitConverterHelper","de.jensklingenberg.ktorfit.internal", "_converter") +val converterHelper = KtorfitClass("KtorfitConverterHelper","de.jensklingenberg.ktorfit.internal", "_helper") val internalApi = ClassName("de.jensklingenberg.ktorfit.internal", "InternalKtorfitApi") 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 c0b6dff3f..5560deb3f 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 @@ -20,8 +20,8 @@ fun getUrlCode(params: List, methodAnnotation: HttpMethodAnnotati "" } else { params.firstOrNull { it.hasAnnotation() }?.let { parameterData -> - "(${converterHelper.objectName}.baseUrl.takeIf{ !${parameterData.name}.startsWith(\"http\")} ?: \"\") + " - } ?: "${converterHelper.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/test/kotlin/de/jensklingenberg/ktorfit/HttpAnnotationTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/HttpAnnotationTest.kt index 0c967f902..328de5376 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/HttpAnnotationTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/HttpAnnotationTest.kt @@ -96,7 +96,7 @@ interface TestService { val expectedFunctionText = """val _ext: HttpRequestBuilder.() -> Unit = { method = HttpMethod.parse("GET2") url{ - takeFrom(_converter.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 1093d40b9..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(_converter.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(_converter.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(_converter.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(_converter.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(_converter.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 f7a063704..75246bdf5 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestConverterTextKtTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/RequestConverterTextKtTest.kt @@ -17,7 +17,7 @@ class RequestConverterTextKtTest { @Test fun generateCorrectFunction() { val expected = """public fun TestFunction() { - val test1: com.example.Test = _converter.convertParameterType(test1,test1::class,com.example.Test::class) + val test1: com.example.Test = _helper.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 069b79353..8a027e31a 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 = _converter.convertParameterType(postId,postId::class,Int::class)""" + val expectedFunctionSource = """val postId: Int = _helper.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 0179647a2..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(_converter.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 313ea5e36..95fab46e1 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 _converter.suspendRequest(_typeData,_ext)!!""" + val expectedFunctionText = """return _helper.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 f5f62047b..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(_converter.baseUrl + "user") + takeFrom(_ktorfit.baseUrl + "user") }""" val source = SourceFile.kotlin( @@ -63,7 +63,7 @@ interface TestService { val expectedFunctionText = """url{ - takeFrom(_converter.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(_converter.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((_converter.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(_converter.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 c92db42e3..b7423e313 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(_converter.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((_converter.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((_converter.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", null)) val params = listOf(parameterData) val text = getUrlCode(params, HttpMethodAnnotation("", HttpMethod.GET), "") - assertEquals("url{\ntakeFrom(_converter.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(_converter.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 f6b4be57a..f8270366c 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/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun create (Lde/jensklingenberg/ktorfit/internal/KtorfitInterface;)Ljava/lang/Object; - public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/KtorfitInterface;ILjava/lang/Object;)Ljava/lang/Object; + public final fun create (Lde/jensklingenberg/ktorfit/internal/ClassProvider;)Ljava/lang/Object; + public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/ClassProvider;ILjava/lang/Object;)Ljava/lang/Object; public final fun getBaseUrl ()Ljava/lang/String; public final fun getHttpClient ()Lio/ktor/client/HttpClient; public final fun nextResponseConverter (Lde/jensklingenberg/ktorfit/converter/Converter$Factory;Lde/jensklingenberg/ktorfit/converter/TypeData;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter; @@ -114,19 +114,17 @@ public final class de/jensklingenberg/ktorfit/converter/TypeData$Companion { 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 class de/jensklingenberg/ktorfit/internal/ClassProvider { + public abstract fun create (Lde/jensklingenberg/ktorfit/Ktorfit;)Ljava/lang/Object; +} + public abstract interface annotation class de/jensklingenberg/ktorfit/internal/InternalKtorfitApi : java/lang/annotation/Annotation { } 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 getBaseUrl ()Ljava/lang/String; public final fun request (Lde/jensklingenberg/ktorfit/converter/TypeData;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun suspendRequest (Lde/jensklingenberg/ktorfit/converter/TypeData;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public abstract interface class de/jensklingenberg/ktorfit/internal/KtorfitInterface { - public abstract fun get_converter ()Lde/jensklingenberg/ktorfit/internal/KtorfitConverterHelper; - public abstract fun set_converter (Lde/jensklingenberg/ktorfit/internal/KtorfitConverterHelper;)V -} - diff --git a/ktorfit-lib-core/api/jvm/ktorfit-lib-core.api b/ktorfit-lib-core/api/jvm/ktorfit-lib-core.api index f6b4be57a..f8270366c 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/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun create (Lde/jensklingenberg/ktorfit/internal/KtorfitInterface;)Ljava/lang/Object; - public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/KtorfitInterface;ILjava/lang/Object;)Ljava/lang/Object; + public final fun create (Lde/jensklingenberg/ktorfit/internal/ClassProvider;)Ljava/lang/Object; + public static synthetic fun create$default (Lde/jensklingenberg/ktorfit/Ktorfit;Lde/jensklingenberg/ktorfit/internal/ClassProvider;ILjava/lang/Object;)Ljava/lang/Object; public final fun getBaseUrl ()Ljava/lang/String; public final fun getHttpClient ()Lio/ktor/client/HttpClient; public final fun nextResponseConverter (Lde/jensklingenberg/ktorfit/converter/Converter$Factory;Lde/jensklingenberg/ktorfit/converter/TypeData;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter; @@ -114,19 +114,17 @@ public final class de/jensklingenberg/ktorfit/converter/TypeData$Companion { 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 class de/jensklingenberg/ktorfit/internal/ClassProvider { + public abstract fun create (Lde/jensklingenberg/ktorfit/Ktorfit;)Ljava/lang/Object; +} + public abstract interface annotation class de/jensklingenberg/ktorfit/internal/InternalKtorfitApi : java/lang/annotation/Annotation { } 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 getBaseUrl ()Ljava/lang/String; public final fun request (Lde/jensklingenberg/ktorfit/converter/TypeData;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun suspendRequest (Lde/jensklingenberg/ktorfit/converter/TypeData;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public abstract interface class de/jensklingenberg/ktorfit/internal/KtorfitInterface { - public abstract fun get_converter ()Lde/jensklingenberg/ktorfit/internal/KtorfitConverterHelper; - public abstract fun set_converter (Lde/jensklingenberg/ktorfit/internal/KtorfitConverterHelper;)V -} - 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 6caed7db8..bfdf92724 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 @@ -75,15 +75,15 @@ public class Ktorfit private constructor( /** * This will return an implementation of [T] if [T] is an interface * with Ktorfit annotations. - * @param data Please keep the default parameter, it will be replaced + * @param classProvider Please keep the default parameter, it will be replaced * by the compiler plugin */ - public fun create(data: KtorfitInterface? = null): T { - if (data == null) { + public fun create(classProvider: ClassProvider? = null): T { + + if (classProvider == null) { throw IllegalArgumentException(ENABLE_GRADLE_PLUGIN) } - data._converter = KtorfitConverterHelper(this) - return data as T + return classProvider.create(this) } diff --git a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper.kt b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper.kt index 0d862bbbd..7cffc3a64 100644 --- a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper.kt +++ b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitConverterHelper.kt @@ -21,7 +21,6 @@ import kotlin.reflect.cast public class KtorfitConverterHelper(private val ktorfit: Ktorfit) { private val httpClient: HttpClient = ktorfit.httpClient - public val baseUrl: String = ktorfit.baseUrl /** * This will handle all requests for functions without suspend modifier @@ -47,7 +46,7 @@ public class KtorfitConverterHelper(private val ktorfit: Ktorfit) { return if (typeIsNullable) { null } else { - throw IllegalStateException("Add a ResponseConverter for " + returnTypeData.qualifiedName + " or make function suspend") + throw IllegalStateException("Add a ResponseConverter for " + returnTypeData.typeInfo + " or make function suspend") } } @@ -79,7 +78,7 @@ public class KtorfitConverterHelper(private val ktorfit: Ktorfit) { return it.convert(result) as ReturnType? } - throw IllegalStateException("No SuspendResponseConverter found to convert ${typeData.qualifiedName}") + throw IllegalStateException("No SuspendResponseConverter found to convert ${typeData.typeInfo}") } catch (exception: Exception) { val typeIsNullable = typeData.typeInfo.kotlinType?.isMarkedNullable ?: false diff --git a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitInterface.kt b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitInterface.kt index b3f2d48d0..b5d1e258a 100644 --- a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitInterface.kt +++ b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/internal/KtorfitInterface.kt @@ -1,7 +1,7 @@ package de.jensklingenberg.ktorfit.internal -@OptIn(InternalKtorfitApi::class) -public interface KtorfitInterface{ - public var _converter: KtorfitConverterHelper -} +import de.jensklingenberg.ktorfit.Ktorfit +public interface ClassProvider { + public fun create(_ktorfit: Ktorfit): T +} \ No newline at end of file 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..ab9a8dad1 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(_BodyTestApiProvider()).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..481809941 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 @@ -6,7 +6,6 @@ import de.jensklingenberg.ktorfit.http.GET import io.ktor.client.* import io.ktor.client.request.* import kotlinx.coroutines.runBlocking -import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Test @@ -71,7 +70,7 @@ class BuilderTest { val ktorfit = Ktorfit.Builder().baseUrl(testBaseUrl, false).httpClient(HttpClient(engine)).build() runBlocking { - ktorfit.create(_BuilderTestApiImpl()).checkIfBaseUrlIsSetWhenUrlCheckIsDisabled() + ktorfit.create(_BuilderTestApiProvider()).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 ce520e692..8a9ed36c7 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 @@ -68,7 +68,7 @@ class ConverterFactoryTest { .build() runBlocking { - ktorfit.create(_ConverterFactoryTestApiImpl()).suspendClientException() + ktorfit.create(_ConverterFactoryTestApiProvider()).suspendClientException() } @@ -113,7 +113,7 @@ class ConverterFactoryTest { .build() runBlocking { - ktorfit.create(_ConverterFactoryTestApiImpl()).clientException().collect() + ktorfit.create(_ConverterFactoryTestApiProvider()).clientException().collect() } 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 f5c27929f..7bf144f42 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(_ClientTestApiProvider()).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(_ClientTestApiProvider()).converterMissing() } } catch (exception: 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(_ClientTestApiProvider()).whenUrlValueContainsBaseUrl_ThenRemoveBaseUrl() } } catch (ex: Exception) { diff --git a/sandbox/src/commonMain/kotlin/com/example/api/GithubService.kt b/sandbox/src/commonMain/kotlin/com/example/api/GithubService.kt index 3cb4897e3..53f2b16be 100644 --- a/sandbox/src/commonMain/kotlin/com/example/api/GithubService.kt +++ b/sandbox/src/commonMain/kotlin/com/example/api/GithubService.kt @@ -24,7 +24,6 @@ interface GithubService { @POST("repos/foso/experimental/issues") suspend fun createIssue2(@Body body: Issuedata, @Header("Acci") headi: String?): Call> - @Headers( "Accept: application/vnd.github.v3+json", "Authorization: token ghp_abcdefgh", @@ -41,4 +40,4 @@ interface GithubService { @GET("repos/{owner}/{repo}/commits") fun listCommits(@Path owner: String, @Path repo: String): Flow> -} \ No newline at end of file +} diff --git a/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvMMain.kt b/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvMMain.kt index 0fbde3275..336a0218a 100644 --- a/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvMMain.kt +++ b/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvMMain.kt @@ -2,10 +2,13 @@ package de.jensklingenberg.ktorfit.demo import com.example.UserFactory +import com.example.api.API import com.example.api.JsonPlaceHolderApi +import com.example.api._APIImpl import com.example.model.ExampleApi import com.example.model.MyOwnResponse import com.example.model.MyOwnResponseConverterFactory +import de.jensklingenberg.ktorfit.Ktorfit import de.jensklingenberg.ktorfit.converter.CallConverterFactory import de.jensklingenberg.ktorfit.converter.FlowConverterFactory import de.jensklingenberg.ktorfit.ktorfit @@ -38,6 +41,7 @@ val jvmClient = HttpClient { val jvmKtorfit = ktorfit { baseUrl(JsonPlaceHolderApi.baseUrl) httpClient(jvmClient) + } @@ -53,11 +57,13 @@ val userKtorfit = ktorfit { ) } +val api : ExampleApi = userKtorfit.create() + fun main() { runBlocking { - val user = userKtorfit.create().getUserResponse() + val user = api.getUserResponse() when (user) { is MyOwnResponse.Success -> { diff --git a/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvmPlaceHolderApi.kt b/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvmPlaceHolderApi.kt index 8f4890924..2bdb9b061 100644 --- a/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvmPlaceHolderApi.kt +++ b/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvmPlaceHolderApi.kt @@ -7,7 +7,7 @@ import de.jensklingenberg.ktorfit.Call import de.jensklingenberg.ktorfit.http.* import io.ktor.client.statement.* -interface JvmPlaceHolderApi : StarWarsApi { +internal interface JvmPlaceHolderApi : StarWarsApi { @GET("people/{id}/") suspend fun getPersonById2(@Path("id") peopleId: Int): People diff --git a/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/QueryTestApi.kt b/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/QueryTestApi.kt index 596d55aa4..ed9614afd 100644 --- a/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/QueryTestApi.kt +++ b/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/QueryTestApi.kt @@ -7,16 +7,20 @@ import ktorfit.Test interface QueryTestApi { @GET("people/{id}/") - suspend fun testQueryWithEncodedString(@Path("id") peopleId: Int, @Query("huhu",true) name: String?,@Query("huhu2",false) name2: String): People + suspend fun testQueryWithEncodedString( + @Path("id") peopleId: Int, + @Query("huhu", true) name: String?, + @Query("huhu2", false) name2: String + ): People @GET("people/{id}/") - suspend fun testQueryWithEncodedInt(@Path("id") peopleId: Int, @Query("huhu",true) name: Int): People + suspend fun testQueryWithEncodedInt(@Path("id") peopleId: Int, @Query("huhu", true) name: Int): People @GET("people/{id}/") - suspend fun testQueryWithString(@Path("id") peopleId: Int, @Query("huhu",false) name: String): People + suspend fun testQueryWithString(@Path("id") peopleId: Int, @Query("huhu", false) name: String): People @GET("people/{id}/") - suspend fun testQueryWithEncodedArray(@Path("id") peopleId: Int, @Query("huhu",true) name: Array): People + suspend fun testQueryWithEncodedArray(@Path("id") peopleId: Int, @Query("huhu", true) name: Array): People @GET("people/{id}/") suspend fun testQueryWithList(@Path("id") peopleId: Int, @Query("huhu") name: List): People @@ -31,8 +35,11 @@ interface QueryTestApi { suspend fun testQueryNameList(@Path("id") peopleId: Int, @QueryName(false) name: List): People @GET("people/{id}/") - suspend fun testQueryEncodedMap(@Path("id") peopleId: Int, @QueryMap name: Map?,@QueryMap(true) name2: Map?): People - + suspend fun testQueryEncodedMap( + @Path("id") peopleId: Int, + @QueryMap name: Map?, + @QueryMap(true) name2: Map? + ): People } \ No newline at end of file