From 80e02e7ad6e0ffb7755f80fa158ef4343c41bdea Mon Sep 17 00:00:00 2001 From: Dewan Tawsif Date: Wed, 5 Feb 2025 19:03:05 +0600 Subject: [PATCH] Properly rename file and add another extension function --- docs/requests.md | 2 +- .../ktorfit/{annotations.kt => Annotations.kt} | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) rename ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/{annotations.kt => Annotations.kt} (53%) diff --git a/docs/requests.md b/docs/requests.md index 6add24b32..a715355c6 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -226,7 +226,7 @@ val result = secondApi.getCommentsById("3") { Then you can use the extension function to set additional configuration. The RequestBuilder will be applied last after everything that is set by Ktorfit ## Annotations -Function annotations are available in the request object with their respective values via the `annotation` extension (`HttpRequestBuilder.annotations`) +Function annotations are available in the request object with their respective values via the `annotation` extension (`HttpRequest.annotations` or `HttpRequestBuilder.annotations`) Do note that `OptIn` annotation is not included in the returned list diff --git a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/annotations.kt b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Annotations.kt similarity index 53% rename from ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/annotations.kt rename to ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Annotations.kt index 302e17a3f..f9459d466 100644 --- a/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/annotations.kt +++ b/ktorfit-lib-core/src/commonMain/kotlin/de/jensklingenberg/ktorfit/Annotations.kt @@ -1,9 +1,13 @@ package de.jensklingenberg.ktorfit +import io.ktor.client.request.HttpRequest import io.ktor.client.request.HttpRequestBuilder import io.ktor.util.AttributeKey public val annotationsAttributeKey: AttributeKey> = AttributeKey("__ktorfit_attribute_annotations") +public val HttpRequest.annotations: List + inline get() = attributes.getOrNull(annotationsAttributeKey) ?: emptyList() + public val HttpRequestBuilder.annotations: List - get() = attributes.getOrNull(annotationsAttributeKey) ?: emptyList() + inline get() = attributes.getOrNull(annotationsAttributeKey) ?: emptyList()