-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include function annotations in request attribute
- Loading branch information
1 parent
278765b
commit d24d726
Showing
10 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...rc/main/kotlin/de/jensklingenberg/ktorfit/reqBuilderExtension/AttributesCodeGeneration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.jensklingenberg.ktorfit.reqBuilderExtension | ||
|
||
import com.squareup.kotlinpoet.AnnotationSpec | ||
import com.squareup.kotlinpoet.ksp.toAnnotationSpec | ||
import de.jensklingenberg.ktorfit.model.annotations.CustomHttp | ||
import de.jensklingenberg.ktorfit.model.annotations.HttpMethodAnnotation | ||
import de.jensklingenberg.ktorfit.model.annotationsAttributeKey | ||
import de.jensklingenberg.ktorfit.utils.toClassName | ||
|
||
fun getAttributesCode(rawAnnotation: List<AnnotationSpec>): String { | ||
val annotations = rawAnnotation.joinToString( | ||
separator = ",\n", | ||
prefix = "listOf(\n", | ||
postfix = ",\n)", | ||
) { annotation -> | ||
annotation | ||
.members | ||
.joinToString { it.toString() } | ||
.let { "${annotation.toClassName().simpleName}($it)" } | ||
} | ||
|
||
return "attributes.put(${annotationsAttributeKey.name}, $annotations)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/utils/AnnotationSpecExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package de.jensklingenberg.ktorfit.utils | ||
|
||
import com.squareup.kotlinpoet.AnnotationSpec | ||
import com.squareup.kotlinpoet.ClassName | ||
import com.squareup.kotlinpoet.ParameterizedTypeName | ||
|
||
fun AnnotationSpec.toClassName(): ClassName { | ||
return if (typeName is ClassName) { | ||
typeName as ClassName | ||
} else { | ||
(typeName as ParameterizedTypeName).rawType | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/annotations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package de.jensklingenberg.ktorfit | ||
|
||
import io.ktor.client.request.HttpRequestBuilder | ||
import io.ktor.util.AttributeKey | ||
|
||
public val annotationsAttributeKey: AttributeKey<List<Any>> = AttributeKey("annotations") | ||
|
||
public val HttpRequestBuilder.annotations: List<Any> | ||
get() = attributes.getOrNull(annotationsAttributeKey) ?: emptyList() |