Skip to content

Commit 7ad8951

Browse files
wing328rlnt
andauthored
[Kotlin] Replace deprecated Ktor base64 encoding with Kotlin std library call (#23345)
* replace deprecated Ktor base64 encoding with Kotlin std library call fixes #22808 * update kotlin samples --------- Co-authored-by: rlnt <relentless@rlnt.dev>
1 parent b0d4c13 commit 7ad8951

File tree

12 files changed

+24
-24
lines changed
  • modules/openapi-generator/src/main/resources/kotlin-client/libraries
  • samples/client/petstore
    • kotlin-array-simple-string-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth
    • kotlin-bigdecimal-default-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth
    • kotlin-default-values-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth
    • kotlin-enum-integers-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth
    • kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/auth
    • kotlin-jvm-ktor-jackson/src/main/kotlin/org/openapitools/client/auth
    • kotlin-jvm-ktor-kotlinx_serialization/src/main/kotlin/org/openapitools/client/auth
    • kotlin-multiplatform-allOf-discriminator/src/commonMain/kotlin/org/openapitools/client/auth
    • kotlin-multiplatform-kotlinx-datetime/src/commonMain/kotlin/org/openapitools/client/auth
    • kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth

12 files changed

+24
-24
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package {{packageName}}.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}class HttpBasicAuth : Authentication {
66
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var username: String? = null
@@ -9,7 +9,7 @@ import io.ktor.util.encodeBase64
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package {{packageName}}.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}class HttpBasicAuth : Authentication {
66
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var username: String? = null
@@ -9,7 +9,7 @@ import io.ktor.util.encodeBase64
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openapitools.client.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
class HttpBasicAuth : Authentication {
66
var username: String? = null
@@ -9,7 +9,7 @@ class HttpBasicAuth : Authentication {
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openapitools.client.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
class HttpBasicAuth : Authentication {
66
var username: String? = null
@@ -9,7 +9,7 @@ class HttpBasicAuth : Authentication {
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openapitools.client.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
class HttpBasicAuth : Authentication {
66
var username: String? = null
@@ -9,7 +9,7 @@ class HttpBasicAuth : Authentication {
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openapitools.client.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
class HttpBasicAuth : Authentication {
66
var username: String? = null
@@ -9,7 +9,7 @@ class HttpBasicAuth : Authentication {
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openapitools.client.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
class HttpBasicAuth : Authentication {
66
var username: String? = null
@@ -9,7 +9,7 @@ class HttpBasicAuth : Authentication {
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openapitools.client.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
class HttpBasicAuth : Authentication {
66
var username: String? = null
@@ -9,7 +9,7 @@ class HttpBasicAuth : Authentication {
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openapitools.client.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
class HttpBasicAuth : Authentication {
66
var username: String? = null
@@ -9,7 +9,7 @@ class HttpBasicAuth : Authentication {
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.openapitools.client.auth
22

3-
import io.ktor.util.encodeBase64
3+
import kotlin.io.encoding.Base64
44

55
class HttpBasicAuth : Authentication {
66
var username: String? = null
@@ -9,7 +9,7 @@ class HttpBasicAuth : Authentication {
99
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
1010
if (username == null && password == null) return
1111
val str = (username ?: "") + ":" + (password ?: "")
12-
val auth = str.encodeBase64()
12+
val auth = Base64.encode(str.encodeToByteArray())
1313
headers["Authorization"] = "Basic $auth"
1414
}
1515
}

0 commit comments

Comments
 (0)