Skip to content

Commit 0c92997

Browse files
committed
fix(kotlin): redundant apiKey setter
1 parent a106640 commit 0c92997

File tree

2 files changed

+10
-9
lines changed
  • clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/transport/internal
  • templates/kotlin

2 files changed

+10
-9
lines changed

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/transport/internal/KtorRequester.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class KtorRequester(
4343
httpClient.config {
4444
defaultRequest {
4545
headers {
46+
remove(HEADER_APIKEY)
4647
append(HEADER_APIKEY, apiKey)
4748
}
4849
}

templates/kotlin/api.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ import kotlinx.serialization.json.*
1212
{{#operations}}
1313
public class {{classname}}(
1414
override val appId: String,
15-
override var apiKey: String,
15+
apiKey: String,
1616
{{#hasRegionalHost}}
1717
public val region: String{{#fallbackToAliasHost}}? = null{{/fallbackToAliasHost}},
1818
{{/hasRegionalHost}}
1919
override val options: ClientOptions = ClientOptions(),
2020
) : ApiClient {
2121
22+
public override var apiKey: String = ""
23+
set(value) {
24+
field = value
25+
requester.setApiKey(value)
26+
}
27+
2228
init {
2329
require(appId.isNotBlank()) { "`appId` is missing." }
2430
require(apiKey.isNotBlank()) { "`apiKey` is missing." }
31+
32+
this.apiKey = apiKey
2533
}
2634

2735
override val requester: Requester = requesterOf(clientName = "{{{baseName}}}", appId = appId, apiKey = apiKey, options = options) {
@@ -55,14 +63,6 @@ public class {{classname}}(
5563
{{/hostsWithoutVariables.size}}
5664
}
5765

58-
/**
59-
* Helper method to switch the API key used to authenticate requests.
60-
*/
61-
public fun setApiKey(apiKey: String) {
62-
this.apiKey = apiKey
63-
this.requester.setApiKey(apiKey)
64-
}
65-
6666
{{#operation}}
6767

6868
/**

0 commit comments

Comments
 (0)