diff --git a/example/AndroidOnlyExample/app/src/main/java/de/jensklingenberg/androidonlyexample/GitHubService.kt b/example/AndroidOnlyExample/app/src/main/java/de/jensklingenberg/androidonlyexample/GitHubService.kt new file mode 100644 index 000000000..5fe47f282 --- /dev/null +++ b/example/AndroidOnlyExample/app/src/main/java/de/jensklingenberg/androidonlyexample/GitHubService.kt @@ -0,0 +1,12 @@ +package de.jensklingenberg.androidonlyexample + +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.Path + +interface GitHubService { + @GET("repos/{user}/{repo}/releases/latest") + suspend fun getLatestRelease( + @Path("user") user: String, + @Path("repo") repo: String, + ): String +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 9d7d46f55..656b96f4d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,7 +22,7 @@ SONATYPE_STAGING_PROFILE=de.jensklingenberg org.gradle.configureondemand=false kapt.include.compile.classpath=false - +kotlin.native.ignoreDisabledTargets=true kotlin.native.binary.freezing=disabled kotlin.mpp.enableGranularSourceSetsMetadata=true ksp.version.check=false diff --git a/ktorfit-ksp/build.gradle.kts b/ktorfit-ksp/build.gradle.kts index 4898144a0..2add2c95e 100644 --- a/ktorfit-ksp/build.gradle.kts +++ b/ktorfit-ksp/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { testImplementation("junit:junit:4.13.2") testImplementation("com.github.tschuchortdev:kotlin-compile-testing-ksp:1.4.8") implementation("com.squareup:kotlinpoet:1.11.0") + implementation("com.squareup:kotlinpoet-ksp:1.11.0") testImplementation("com.google.truth:truth:1.1.3") compileOnly ("com.google.auto.service:auto-service:1.0.1") kapt ("com.google.auto.service:auto-service:1.0.1") diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/generator/ClassGenerator.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/generator/ClassGenerator.kt index 28c026108..d7d63d374 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/generator/ClassGenerator.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/generator/ClassGenerator.kt @@ -62,6 +62,7 @@ fun getFileSpec(classData: ClassData): FileSpec { .addImport("de.jensklingenberg.ktorfit.internal", "KtorfitClient") .addType( TypeSpec.classBuilder(implClassName) + .addModifiers(classData.modifiers) .addSuperinterface(ClassName(classData.packageName, classData.name)) .addKtorfitSuperInterface(classData.superClasses) .primaryConstructor( 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 54d1f846c..ab2d88c5d 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 @@ -1,6 +1,7 @@ package de.jensklingenberg.ktorfit.model import com.google.devtools.ksp.symbol.KSPropertyDeclaration +import com.squareup.kotlinpoet.KModifier /** * @param superClasses List of qualifiedNames of interface that a Ktorfit interface extends @@ -11,5 +12,6 @@ data class ClassData( val functions: List, val imports: List, val superClasses: List = emptyList(), - val properties: List = emptyList() + val properties: List = emptyList(), + val modifiers: List = emptyList() ) \ No newline at end of file diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitError.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitError.kt index 658f1652a..0aa896052 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitError.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitError.kt @@ -33,6 +33,7 @@ class KtorfitError { const val COULD_NOT_FIND_ANY_KTORFIT_ANNOTATIONS_IN_CLASS = "Could not find any Ktorfit annotations in class" fun MISSING_EITHER_KEYWORD_URL_OrURL_PARAMETER(keyword: String) = "Missing either @$keyword URL or @Url parameter" const val JAVA_INTERFACES_ARE_NOT_SUPPORTED = "Java Interfaces are not supported" + const val INTERNAL_INTERFACES_ARE_NOT_SUPPORTED = "internal Interfaces are not supported" const val INTERFACE_NEEDS_TO_HAVE_A_PACKAGE = "Interface needs to have a package" const val ONLY_ONE_HTTP_METHOD_IS_ALLOWED = "Only one HTTP method is allowed." const val FORM_URL_ENCODED_CAN_ONLY_BE_SPECIFIED_ON_HTTP_METHODS_WITH_REQUEST_BODY = "FormUrlEncoded can only be specified on HTTP methods with request body (e.g., @POST)." diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/parser/ClassParser.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/parser/ClassParser.kt index ad5559464..6eab62b2c 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/parser/ClassParser.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/parser/ClassParser.kt @@ -3,10 +3,13 @@ package de.jensklingenberg.ktorfit.parser import com.google.devtools.ksp.getDeclaredFunctions import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.Modifier +import com.squareup.kotlinpoet.ksp.toKModifier import de.jensklingenberg.ktorfit.ktorfitError import de.jensklingenberg.ktorfit.model.ClassData import de.jensklingenberg.ktorfit.model.FunctionData import de.jensklingenberg.ktorfit.model.KtorfitError.Companion.INTERFACE_NEEDS_TO_HAVE_A_PACKAGE +import de.jensklingenberg.ktorfit.model.KtorfitError.Companion.INTERNAL_INTERFACES_ARE_NOT_SUPPORTED import de.jensklingenberg.ktorfit.resolveTypeName import java.io.File @@ -58,5 +61,17 @@ fun toClassData(ksClassDeclaration: KSClassDeclaration, logger: KSPLogger): Clas if (packageName.isEmpty()) { logger.ktorfitError(INTERFACE_NEEDS_TO_HAVE_A_PACKAGE, ksClassDeclaration) } - return ClassData(className, packageName, functionDataList, imports, supertypes, properties) + + if (ksClassDeclaration.modifiers.contains(Modifier.INTERNAL)) { + logger.ktorfitError(INTERNAL_INTERFACES_ARE_NOT_SUPPORTED, ksClassDeclaration) + } + + return ClassData( + className, + packageName, + functionDataList, + imports, + supertypes, + properties, + modifiers = ksClassDeclaration.modifiers.mapNotNull { it.toKModifier() }) } diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/requestData/HeadersArgumentText.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/requestData/HeadersArgumentText.kt index c8da6557f..817d9199a 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/requestData/HeadersArgumentText.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/requestData/HeadersArgumentText.kt @@ -20,7 +20,10 @@ fun getHeadersArgumentText( val paramsWithHeaderMap = paramList.filter { it.hasAnnotation() } if (functionAnnotations.any { it is FormUrlEncoded }) { - headerList.add(Pair("\"Content-Type\"", "\"application/x-www-form-urlencoded\"")) + /** + * Can't add Content Type Header, because it leads to Ktor issues https://github.com/ktorio/ktor/issues/1127 + */ + // headerList.add(Pair("\"Content-Type\"", "\"application/x-www-form-urlencoded\"")) } paramsWithHeaderAnno.forEach { myParam -> diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/FormUrlEncodedAnnotationsTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/FormUrlEncodedAnnotationsTest.kt index 211d162cf..40eca88b1 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/FormUrlEncodedAnnotationsTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/FormUrlEncodedAnnotationsTest.kt @@ -70,7 +70,6 @@ interface TestService { val expectedBodyDataArgumentText = """public override suspend fun test(id: String): String { val requestData = RequestData(method="POST", relativeUrl="user", - headers = listOf(HeaderData("Content-Type","application/x-www-form-urlencoded")), fields = listOf(FieldData(false,"id",id,FieldType.FIELD)), qualifiedRawTypeName="kotlin.String") diff --git a/local.properties b/local.properties index c5b3cc9e7..ba63c14a9 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Sun May 08 21:33:07 CEST 2022 -sdk.dir=/Users/jensklingenberg/Library/Android/sdk +#Thu May 26 21:30:01 CEST 2022 +sdk.dir=/home/jens/Code/Android/Sdk