From 737ab5c73da8c51b4b5aa94ea23551d91b95b22d Mon Sep 17 00:00:00 2001 From: Jens Klingenberg Date: Tue, 4 Feb 2025 19:40:18 +0100 Subject: [PATCH] Fix headers code generation #752 (#772) --- .editorconfig | 3 ++- docs/CHANGELOG.md | 4 ++++ gradle/libs.versions.toml | 2 +- .../ktorfit/model/annotations/ParameterAnnotation.kt | 4 ++-- .../de/jensklingenberg/ktorfit/QueryAnnotationsTest.kt | 9 +++------ .../commonMain/kotlin/com/example/model/ExampleApi.kt | 3 +++ 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.editorconfig b/.editorconfig index bf5fe28a0..296c24c83 100644 --- a/.editorconfig +++ b/.editorconfig @@ -18,4 +18,5 @@ ktlint_standard_comment-wrapping = disabled # noinspection EditorConfigKeyCorrectness ktlint_standard_block-comment-initial-star-alignment = disabled # noinspection EditorConfigKeyCorrectness -ktlint_standard_no-single-line-block-comment = disabled \ No newline at end of file +ktlint_standard_no-single-line-block-comment = disabled +max_line_length=off \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c8cd7b166..7529d2707 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,7 @@ Note: This project needs KSP to work and every new Ktorfit with an update of the But there is no intent to bump the Ktorfit major version for every KSP update. # Unreleased +## Added - Provide option to not use the compiler plugin #764 You can now set the Kotlin version for the compiler plugin. By default, it will use the Kotlin version of the project. You can set it to "-" to disable the plugin. @@ -20,6 +21,9 @@ ktorfit{ } ``` +## Fixed +- @Headers annotation produces unexpected newline in generated code by ksp plugin #752 + # [2.2.0]() * Supported Kotlin version: 2.0.0; 2.0.10; 2.0.20, 2.1.0-Beta1; 2.0.21-RC, 2.0.21, 2.1.0-RC, 2.1.0-RC2, 2.1.0, 2.1.10 * Supported KSP version: 1.0.27, 1.0.28, 1.0.29 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9e3074d26..3f16c27ad 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ detekt = "1.23.7" junit = "4.13.2" kctfork = "0.7.0" kotlin = "2.1.10" -kotlinPoet = "1.18.1" +kotlinPoet = "2.0.0" kspVersion = "2.1.10-1.0.29" groupId = "de.jensklingenberg.ktorfit" diff --git a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/annotations/ParameterAnnotation.kt b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/annotations/ParameterAnnotation.kt index 2faa94ec3..825b9584e 100644 --- a/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/annotations/ParameterAnnotation.kt +++ b/ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/annotations/ParameterAnnotation.kt @@ -128,7 +128,7 @@ fun KSValueParameter.getParamAnnotationList(logger: KSPLogger): List entry.value?.let{ parameter(entry.key, \"\${entry.value}\") }\n" + - " }\n" + - " testQueryMap2?.forEach { entry -> entry.value?.let{ encodedParameters.append(entry.key,\n" + - " \"\${entry.value}\") } }\n" + + " testQueryMap?.forEach { entry -> entry.value?.let{ parameter(entry.key, \"\${entry.value}\") } }\n" + + " testQueryMap2?.forEach { entry -> entry.value?.let{ encodedParameters.append(entry.key, \"\${entry.value}\") } }\n" + " }" val compilation = getCompilation(listOf(source)) @@ -189,8 +187,7 @@ fun example(@Query("name") testQuery: String, @QueryName testQueryName: String, " 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" + - " \"\${entry.value}\") } }\n" + + " name?.forEach { entry -> entry.value?.let{ encodedParameters.append(entry.key, \"\${entry.value}\") } }\n" + " }" val compilation = getCompilation(listOf(source)) diff --git a/sandbox/src/commonMain/kotlin/com/example/model/ExampleApi.kt b/sandbox/src/commonMain/kotlin/com/example/model/ExampleApi.kt index ab95aac6b..6e25dff55 100644 --- a/sandbox/src/commonMain/kotlin/com/example/model/ExampleApi.kt +++ b/sandbox/src/commonMain/kotlin/com/example/model/ExampleApi.kt @@ -2,8 +2,11 @@ package com.example.model import de.jensklingenberg.ktorfit.Response import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.Headers interface ExampleApi { + + @Headers("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0") @GET("example.json") suspend fun getUser(): Response