From a7ff280c6d19f0425d98822df375162e522d1558 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 11:58:34 +0100 Subject: [PATCH 1/9] chore: add script for generating new API version classes #WPB-11975 --- network/build.gradle.kts | 19 +++ .../kalium/network/BackendMetaDataUtil.kt | 36 ++++-- .../api/v6/authenticated/AccessTokenApiV6.kt | 2 +- .../AuthenticatedNetworkContainer.kt | 12 ++ .../UnauthenticatedNetworkContainer.kt | 19 ++- scripts/generate_new_api_version.sh | 108 ++++++++++++++++++ 6 files changed, 179 insertions(+), 17 deletions(-) create mode 100755 scripts/generate_new_api_version.sh diff --git a/network/build.gradle.kts b/network/build.gradle.kts index 7959cb38cda..f12ff9b815c 100644 --- a/network/build.gradle.kts +++ b/network/build.gradle.kts @@ -111,3 +111,22 @@ android { it.enabled = false } } + +tasks.register("generateNewApiVersion") { + group = "custom" + description = "Generates a new API version by calling the generate_new_api_version.sh script" + + val previousApiVersion = project.findProperty("previousApiVersion") as String? ?: "" + val currentApiVersion = project.findProperty("currentApiVersion") as String? ?: "" + val newApiVersion = project.findProperty("newApiVersion") as String? ?: "" + + doFirst { + if (previousApiVersion == "" || currentApiVersion == "" || newApiVersion == "") { + println("Usage: ./gradlew :moduleName:generateNewApiVersion -PpreviousApiVersion= -PcurrentApiVersion= -PnewApiVersion=") + println("Example: ./gradlew :moduleName:generateNewApiVersion -PpreviousApiVersion=5 -PcurrentApiVersion=6 -PnewApiVersion=7") + throw IllegalArgumentException("All parameters (previousApiVersion, currentApiVersion, newApiVersion) must be provided.") + } + } + + commandLine("bash", "./../scripts/generate_new_api_version.sh", previousApiVersion, currentApiVersion, newApiVersion) +} diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt index 1053fd2ecdc..26e501f916c 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt @@ -15,9 +15,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ - -@file:Suppress("MagicNumber") - package com.wire.kalium.network import com.wire.kalium.network.api.unbound.configuration.ApiVersionDTO @@ -25,6 +22,8 @@ import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.unbound.versioning.VersionInfoDTO val SupportedApiVersions = setOf(0, 1, 2, 4, 5) +// You can use scripts/generate_new_api_version.sh or gradle task network:generateNewApiVersion to +// bump API version and generate all needed classes val DevelopmentApiVersions = setOf(6) interface BackendMetaDataUtil { @@ -45,8 +44,13 @@ object BackendMetaDataUtilImpl : BackendMetaDataUtil { developmentApiEnabled: Boolean ): ServerConfigDTO.MetaData { - val allSupportedApiVersions = if (developmentApiEnabled) supportedApiVersions + developmentApiVersions else supportedApiVersions - val apiVersion = commonApiVersion(versionInfoDTO, allSupportedApiVersions, developmentApiEnabled)?.let { maxCommonVersion -> + val allSupportedApiVersions = + if (developmentApiEnabled) supportedApiVersions + developmentApiVersions else supportedApiVersions + val apiVersion = commonApiVersion( + versionInfoDTO, + allSupportedApiVersions, + developmentApiEnabled + )?.let { maxCommonVersion -> ApiVersionDTO.Valid(maxCommonVersion) } ?: run { handleNoCommonVersion(versionInfoDTO.supported, allSupportedApiVersions) @@ -59,16 +63,24 @@ object BackendMetaDataUtilImpl : BackendMetaDataUtil { ) } - private fun commonApiVersion(serverVersion: VersionInfoDTO, supportedApiVersions: Set, developmentAPIEnabled: Boolean): Int? { - val serverSupportedApiVersions: List = if (developmentAPIEnabled && serverVersion.developmentSupported != null) { - serverVersion.supported + serverVersion.developmentSupported!! - } else { - serverVersion.supported - } + private fun commonApiVersion( + serverVersion: VersionInfoDTO, + supportedApiVersions: Set, + developmentAPIEnabled: Boolean + ): Int? { + val serverSupportedApiVersions: List = + if (developmentAPIEnabled && serverVersion.developmentSupported != null) { + serverVersion.supported + serverVersion.developmentSupported!! + } else { + serverVersion.supported + } return serverSupportedApiVersions.intersect(supportedApiVersions).maxOrNull() } - private fun handleNoCommonVersion(serverVersion: List, appVersion: Set): ApiVersionDTO.Invalid { + private fun handleNoCommonVersion( + serverVersion: List, + appVersion: Set + ): ApiVersionDTO.Invalid { return serverVersion.maxOrNull()?.let { maxBEVersion -> appVersion.maxOrNull()?.let { maxAppVersion -> if (maxBEVersion > maxAppVersion) ApiVersionDTO.Invalid.New diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt index a37f21cd1a8..5faf053b0c7 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt @@ -21,6 +21,6 @@ package com.wire.kalium.network.api.v6.authenticated import com.wire.kalium.network.api.v5.authenticated.AccessTokenApiV5 import io.ktor.client.HttpClient -internal class AccessTokenApiV6 internal constructor( +internal open class AccessTokenApiV6 internal constructor( private val httpClient: HttpClient ) : AccessTokenApiV5(httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt index d46fe227c44..ccd602dde35 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt @@ -49,6 +49,7 @@ import com.wire.kalium.network.api.v2.authenticated.networkContainer.Authenticat import com.wire.kalium.network.api.v4.authenticated.networkContainer.AuthenticatedNetworkContainerV4 import com.wire.kalium.network.api.v5.authenticated.networkContainer.AuthenticatedNetworkContainerV5 import com.wire.kalium.network.api.v6.authenticated.networkContainer.AuthenticatedNetworkContainerV6 +import com.wire.kalium.network.api.v7.authenticated.networkContainer.AuthenticatedNetworkContainerV7 import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager import io.ktor.client.HttpClient @@ -188,6 +189,17 @@ interface AuthenticatedNetworkContainer { kaliumLogger ) + 7 -> AuthenticatedNetworkContainerV7( + sessionManager, + selfUserId, + certificatePinning, + mockEngine, + mockWebSocketSession, + kaliumLogger + ) + + // You can use scripts/generate_new_api_version.sh or gradle task network:generateNewApiVersion to + // bump API version and generate all needed classes else -> error("Unsupported version: $version") } } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt index 54a0579d0db..f647f9dcff3 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt @@ -19,21 +19,22 @@ package com.wire.kalium.network.networkContainer import com.wire.kalium.network.UnauthenticatedNetworkClient -import com.wire.kalium.network.api.model.ProxyCredentialsDTO +import com.wire.kalium.network.api.base.unauthenticated.appVersioning.AppVersioningApi import com.wire.kalium.network.api.base.unauthenticated.domainLookup.DomainLookupApi import com.wire.kalium.network.api.base.unauthenticated.login.LoginApi +import com.wire.kalium.network.api.base.unauthenticated.register.RegisterApi import com.wire.kalium.network.api.base.unauthenticated.sso.SSOLoginApi import com.wire.kalium.network.api.base.unauthenticated.verification.VerificationCodeApi -import com.wire.kalium.network.api.base.unauthenticated.appVersioning.AppVersioningApi -import com.wire.kalium.network.api.base.unauthenticated.register.RegisterApi import com.wire.kalium.network.api.base.unbound.configuration.ServerConfigApi -import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.base.unbound.versioning.VersionApi +import com.wire.kalium.network.api.model.ProxyCredentialsDTO +import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.v0.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV0 import com.wire.kalium.network.api.v2.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV2 import com.wire.kalium.network.api.v4.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV4 import com.wire.kalium.network.api.v5.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV5 import com.wire.kalium.network.api.v6.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV6 +import com.wire.kalium.network.api.v7.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV7 import com.wire.kalium.network.session.CertificatePinning import io.ktor.client.engine.HttpClientEngine @@ -120,6 +121,16 @@ interface UnauthenticatedNetworkContainer { developmentApiEnabled = developmentApiEnabled ) + 7 -> UnauthenticatedNetworkContainerV7( + backendLinks = serverConfigDTO, + proxyCredentials = proxyCredentials, + certificatePinning = certificatePinning, + mockEngine = mockEngine, + developmentApiEnabled = developmentApiEnabled + ) + + // You can use scripts/generate_new_api_version.sh or gradle task network:generateNewApiVersion to + // bump API version and generate all needed classes else -> error("Unsupported version: ${serverConfigDTO.metaData.commonApiVersion.version}") } } diff --git a/scripts/generate_new_api_version.sh b/scripts/generate_new_api_version.sh new file mode 100755 index 00000000000..a2671bb3da3 --- /dev/null +++ b/scripts/generate_new_api_version.sh @@ -0,0 +1,108 @@ +#!/bin/bash + +# Makes all paths relative to project root so it can be run from anywhere +parent_path=$( + cd "$(dirname "${BASH_SOURCE[0]}")" || exit + pwd -P +) +cd "$parent_path/.." || exit + +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + echo "Example: $0 5 6 7" + exit 1 +fi + +# Validate that all parameters are integers +if ! [[ "$1" =~ ^[0-9]+$ && "$2" =~ ^[0-9]+$ && "$3" =~ ^[0-9]+$ ]]; then + echo "Error: All parameters must be integers." + exit 1 +fi + +# sometimes we have lower case (i.e. imports) sometimes upper case (i.e. class names) +previousApiVersionLower="v$1" +currentApiVersionLower="v$2" +newApiVersionLower="v$3" + +previousApiVersionUpper="V$1" +currentApiVersionUpper="V$2" +newApiVersionUpper="V$3" + +copy_api_files() { + local source_dir=$1 + local target_dir=$2 + + mkdir -p "$target_dir" + + for file in "$source_dir"/*.kt; do + if [[ -f "$file" ]]; then + content=$(cat "$file") + # package name changed from previous to current version + new_content=$(echo "$content" | sed "s/com\.wire\.kalium\.network\.api\.$currentApiVersionLower\./com.wire.kalium.network.api.$newApiVersionLower./g") + # class name changed from previous to current version + new_content=$(echo "$new_content" | sed "s/\(class .*\)$currentApiVersionUpper/\1$newApiVersionUpper/g") + # imports changed from previous to current version + new_content=$(echo "$new_content" | sed "s/com\.wire\.kalium\.network\.api\.$previousApiVersionLower\./com.wire.kalium.network.api.$currentApiVersionLower./g") + # imports class names changed from previous to current version + new_content=$(echo "$new_content" | sed "s/\(import com\.wire\.kalium\.network\.api\.$currentApiVersionLower\.\)\(.*\)$previousApiVersionUpper/\1\2$currentApiVersionUpper/g") + # class names in extension definition changed from previous to current version + new_content=$(echo "$new_content" | sed "s/\(: \)\(.*\)$previousApiVersionUpper/\1\2$currentApiVersionUpper/g") + # class names in inheritance changed from previous to current version + new_content=$(echo "$new_content" | sed "s/\(: \)\(.*\)$previousApiVersionUpper/\1\2$currentApiVersionUpper/g") + # New file name with newApiVersion + new_filename=$(basename "$file" | sed "s/$currentApiVersionUpper/$newApiVersionUpper/g") + echo "$new_content" >"$target_dir/$new_filename" + echo "Created $new_filename" + fi + done +} + +SOURCE_DIR_UNAUTH="network/src/commonMain/kotlin/com/wire/kalium/network/api/$currentApiVersionLower/unauthenticated" +TARGET_DIR_UNAUTH="network/src/commonMain/kotlin/com/wire/kalium/network/api/$newApiVersionLower/unauthenticated" + +SOURCE_DIR_AUTH="network/src/commonMain/kotlin/com/wire/kalium/network/api/$currentApiVersionLower/authenticated" +TARGET_DIR_AUTH="network/src/commonMain/kotlin/com/wire/kalium/network/api/$newApiVersionLower/authenticated" + +copy_api_files "$SOURCE_DIR_UNAUTH" "$TARGET_DIR_UNAUTH" +copy_api_files "$SOURCE_DIR_AUTH" "$TARGET_DIR_AUTH" + +copy_container_files() { + local source_file="$1" + local target_file="${source_file//$currentApiVersionUpper/$newApiVersionUpper}" + target_file="${target_file//$currentApiVersionLower/$newApiVersionLower}" + if [[ -f "$source_file" ]]; then + mkdir -p "$(dirname "$target_file")" + + # Read the content of the file + content=$(cat "$source_file") + + # Perform replacements on the content + new_content="${content//$currentApiVersionUpper/$newApiVersionUpper}" + new_content="${new_content//$currentApiVersionLower/$newApiVersionLower}" + + # Save the modified content back to the target file + echo "$new_content" >"$target_file" + + echo "Created $target_file" + else + exit 1 + fi +} + +copy_container_files "network/src/commonMain/kotlin/com/wire/kalium/network/api/$currentApiVersionLower/authenticated/networkContainer/AuthenticatedNetworkContainer$currentApiVersionUpper.kt" +copy_container_files "network/src/commonMain/kotlin/com/wire/kalium/network/api/$currentApiVersionLower/unauthenticated/networkContainer/UnauthenticatedNetworkContainer$currentApiVersionUpper.kt" + +echo + +# Add the new API version to DevelopmentApiVersions +# Add the new API version to DevelopmentApiVersions if it does not already contain it +if ! grep -q "$3" network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt; then + sed -i '' "s/\(val DevelopmentApiVersions = setOf(.*\))/\1, $3)/" network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt + echo "Added $3 to DevelopmentApiVersions in BackendMetaDataUtil.kt" +else + echo "$3 is already in DevelopmentApiVersions in BackendMetaDataUtil.kt" +fi + +echo "!!!!!!!" +echo "You must add the new API version to the list of supported API versions in the AuthenticatedNetworkContainer.create() and UnauthenticatedNetworkContainer.create() methods." +echo "!!!!!!!" From 8bf27a6dcf73f1f2bc13cf8ad0c3f0fc65a58c2d Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 12:19:29 +0100 Subject: [PATCH 2/9] detekt --- network/build.gradle.kts | 23 +++++++++++++++---- .../kalium/network/BackendMetaDataUtil.kt | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/network/build.gradle.kts b/network/build.gradle.kts index f12ff9b815c..cc36d89ab09 100644 --- a/network/build.gradle.kts +++ b/network/build.gradle.kts @@ -122,11 +122,26 @@ tasks.register("generateNewApiVersion") { doFirst { if (previousApiVersion == "" || currentApiVersion == "" || newApiVersion == "") { - println("Usage: ./gradlew :moduleName:generateNewApiVersion -PpreviousApiVersion= -PcurrentApiVersion= -PnewApiVersion=") - println("Example: ./gradlew :moduleName:generateNewApiVersion -PpreviousApiVersion=5 -PcurrentApiVersion=6 -PnewApiVersion=7") - throw IllegalArgumentException("All parameters (previousApiVersion, currentApiVersion, newApiVersion) must be provided.") + println( + "Usage: ./gradlew :moduleName:generateNewApiVersion " + + "-PpreviousApiVersion= -PcurrentApiVersion= -PnewApiVersion=" + ) + println( + "Example: ./gradlew :moduleName:generateNewApiVersion " + + "-PpreviousApiVersion=5 -PcurrentApiVersion=6 -PnewApiVersion=7" + ) + throw IllegalArgumentException( + "All parameters (previousApiVersion, " + + "currentApiVersion, newApiVersion) must be provided." + ) } } - commandLine("bash", "./../scripts/generate_new_api_version.sh", previousApiVersion, currentApiVersion, newApiVersion) + commandLine( + "bash", + "./../scripts/generate_new_api_version.sh", + previousApiVersion, + currentApiVersion, + newApiVersion + ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt index 26e501f916c..71d5cffcda2 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt @@ -22,9 +22,10 @@ import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.unbound.versioning.VersionInfoDTO val SupportedApiVersions = setOf(0, 1, 2, 4, 5) +val DevelopmentApiVersions = setOf(6) + // You can use scripts/generate_new_api_version.sh or gradle task network:generateNewApiVersion to // bump API version and generate all needed classes -val DevelopmentApiVersions = setOf(6) interface BackendMetaDataUtil { fun calculateApiVersion( From 60307e6047a0b56f2555763c9aed12048213d005 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 12:27:24 +0100 Subject: [PATCH 3/9] doc fix --- network/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/build.gradle.kts b/network/build.gradle.kts index cc36d89ab09..fce0b545667 100644 --- a/network/build.gradle.kts +++ b/network/build.gradle.kts @@ -123,11 +123,11 @@ tasks.register("generateNewApiVersion") { doFirst { if (previousApiVersion == "" || currentApiVersion == "" || newApiVersion == "") { println( - "Usage: ./gradlew :moduleName:generateNewApiVersion " + + "Usage: ./gradlew :network:generateNewApiVersion " + "-PpreviousApiVersion= -PcurrentApiVersion= -PnewApiVersion=" ) println( - "Example: ./gradlew :moduleName:generateNewApiVersion " + + "Example: ./gradlew :network:generateNewApiVersion " + "-PpreviousApiVersion=5 -PcurrentApiVersion=6 -PnewApiVersion=7" ) throw IllegalArgumentException( From 72d257b2dc5fb6fa78af264afe6e4edc9e0a6488 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 12:28:55 +0100 Subject: [PATCH 4/9] remove v7 changes --- .../networkContainer/AuthenticatedNetworkContainer.kt | 10 ---------- .../UnauthenticatedNetworkContainer.kt | 9 --------- 2 files changed, 19 deletions(-) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt index ccd602dde35..90ab061cc62 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt @@ -49,7 +49,6 @@ import com.wire.kalium.network.api.v2.authenticated.networkContainer.Authenticat import com.wire.kalium.network.api.v4.authenticated.networkContainer.AuthenticatedNetworkContainerV4 import com.wire.kalium.network.api.v5.authenticated.networkContainer.AuthenticatedNetworkContainerV5 import com.wire.kalium.network.api.v6.authenticated.networkContainer.AuthenticatedNetworkContainerV6 -import com.wire.kalium.network.api.v7.authenticated.networkContainer.AuthenticatedNetworkContainerV7 import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager import io.ktor.client.HttpClient @@ -189,15 +188,6 @@ interface AuthenticatedNetworkContainer { kaliumLogger ) - 7 -> AuthenticatedNetworkContainerV7( - sessionManager, - selfUserId, - certificatePinning, - mockEngine, - mockWebSocketSession, - kaliumLogger - ) - // You can use scripts/generate_new_api_version.sh or gradle task network:generateNewApiVersion to // bump API version and generate all needed classes else -> error("Unsupported version: $version") diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt index f647f9dcff3..ca9a0f2f641 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt @@ -34,7 +34,6 @@ import com.wire.kalium.network.api.v2.unauthenticated.networkContainer.Unauthent import com.wire.kalium.network.api.v4.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV4 import com.wire.kalium.network.api.v5.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV5 import com.wire.kalium.network.api.v6.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV6 -import com.wire.kalium.network.api.v7.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV7 import com.wire.kalium.network.session.CertificatePinning import io.ktor.client.engine.HttpClientEngine @@ -121,14 +120,6 @@ interface UnauthenticatedNetworkContainer { developmentApiEnabled = developmentApiEnabled ) - 7 -> UnauthenticatedNetworkContainerV7( - backendLinks = serverConfigDTO, - proxyCredentials = proxyCredentials, - certificatePinning = certificatePinning, - mockEngine = mockEngine, - developmentApiEnabled = developmentApiEnabled - ) - // You can use scripts/generate_new_api_version.sh or gradle task network:generateNewApiVersion to // bump API version and generate all needed classes else -> error("Unsupported version: ${serverConfigDTO.metaData.commonApiVersion.version}") From ac2fe4615e4620c99a622862c970d7fe296ff9b2 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 12:29:53 +0100 Subject: [PATCH 5/9] duplicated doc --- scripts/generate_new_api_version.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_new_api_version.sh b/scripts/generate_new_api_version.sh index a2671bb3da3..1283b22222f 100755 --- a/scripts/generate_new_api_version.sh +++ b/scripts/generate_new_api_version.sh @@ -94,7 +94,6 @@ copy_container_files "network/src/commonMain/kotlin/com/wire/kalium/network/api/ echo -# Add the new API version to DevelopmentApiVersions # Add the new API version to DevelopmentApiVersions if it does not already contain it if ! grep -q "$3" network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt; then sed -i '' "s/\(val DevelopmentApiVersions = setOf(.*\))/\1, $3)/" network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt From 5d404cc6f4b24f9c7fc56be12934551b321e9e0f Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 13:27:19 +0100 Subject: [PATCH 6/9] detekt --- .../kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt index 71d5cffcda2..ffb40872ba4 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt @@ -21,7 +21,12 @@ import com.wire.kalium.network.api.unbound.configuration.ApiVersionDTO import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.api.unbound.versioning.VersionInfoDTO +// They are not truly constants as set is not a primitive type, yet are treated as one in this context +@Suppress("MagicNumber") val SupportedApiVersions = setOf(0, 1, 2, 4, 5) + +// They are not truly constants as set is not a primitive type, yet are treated as one in this context +@Suppress("MagicNumber") val DevelopmentApiVersions = setOf(6) // You can use scripts/generate_new_api_version.sh or gradle task network:generateNewApiVersion to From 82fc9f2c7a6060e2b90dbac84ea961ed37ecdbd8 Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 14:41:24 +0100 Subject: [PATCH 7/9] fix - remove content of new class --- scripts/generate_new_api_version.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/generate_new_api_version.sh b/scripts/generate_new_api_version.sh index 1283b22222f..86395e5dfff 100755 --- a/scripts/generate_new_api_version.sh +++ b/scripts/generate_new_api_version.sh @@ -49,6 +49,8 @@ copy_api_files() { new_content=$(echo "$new_content" | sed "s/\(: \)\(.*\)$previousApiVersionUpper/\1\2$currentApiVersionUpper/g") # class names in inheritance changed from previous to current version new_content=$(echo "$new_content" | sed "s/\(: \)\(.*\)$previousApiVersionUpper/\1\2$currentApiVersionUpper/g") + # Make class definitions empty inside {} + new_content=$(echo "$new_content" | perl -0777 -pe "s|({[\W\w]*\})|\2\{\}|g") # New file name with newApiVersion new_filename=$(basename "$file" | sed "s/$currentApiVersionUpper/$newApiVersionUpper/g") echo "$new_content" >"$target_dir/$new_filename" From 471e63cd90a7a22ccd80a9b29353a4fa9d5dd57d Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Fri, 8 Nov 2024 14:52:41 +0100 Subject: [PATCH 8/9] do not add brackets --- scripts/generate_new_api_version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_new_api_version.sh b/scripts/generate_new_api_version.sh index 86395e5dfff..bf7fa11538d 100755 --- a/scripts/generate_new_api_version.sh +++ b/scripts/generate_new_api_version.sh @@ -50,7 +50,7 @@ copy_api_files() { # class names in inheritance changed from previous to current version new_content=$(echo "$new_content" | sed "s/\(: \)\(.*\)$previousApiVersionUpper/\1\2$currentApiVersionUpper/g") # Make class definitions empty inside {} - new_content=$(echo "$new_content" | perl -0777 -pe "s|({[\W\w]*\})|\2\{\}|g") + new_content=$(echo "$new_content" | perl -0777 -pe "s|({[\W\w]*\})|\2|g") # New file name with newApiVersion new_filename=$(basename "$file" | sed "s/$currentApiVersionUpper/$newApiVersionUpper/g") echo "$new_content" >"$target_dir/$new_filename" From 489f55efa9814c6c18d5da9f67ddacd0bf0815fb Mon Sep 17 00:00:00 2001 From: Damian Kaczmarek Date: Wed, 20 Nov 2024 09:42:23 +0100 Subject: [PATCH 9/9] remove private val --- scripts/generate_new_api_version.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/generate_new_api_version.sh b/scripts/generate_new_api_version.sh index bf7fa11538d..5b2a6c2875a 100755 --- a/scripts/generate_new_api_version.sh +++ b/scripts/generate_new_api_version.sh @@ -51,6 +51,8 @@ copy_api_files() { new_content=$(echo "$new_content" | sed "s/\(: \)\(.*\)$previousApiVersionUpper/\1\2$currentApiVersionUpper/g") # Make class definitions empty inside {} new_content=$(echo "$new_content" | perl -0777 -pe "s|({[\W\w]*\})|\2|g") + # Remove all private val or val + new_content=$(echo "$new_content" | sed "s/\(private \)*val //g") # New file name with newApiVersion new_filename=$(basename "$file" | sed "s/$currentApiVersionUpper/$newApiVersionUpper/g") echo "$new_content" >"$target_dir/$new_filename" @@ -106,4 +108,5 @@ fi echo "!!!!!!!" echo "You must add the new API version to the list of supported API versions in the AuthenticatedNetworkContainer.create() and UnauthenticatedNetworkContainer.create() methods." +echo "Check the generated files for unused parameters." echo "!!!!!!!"