From 6ffb9c62795f3c094d24eb71fdbbe4933ae14356 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 5 Feb 2025 10:38:54 -0600 Subject: [PATCH 1/4] fix!: Remove mutating 'addInterceptor' methods from client config --- .../Config/DefaultClientConfiguration.swift | 5 ----- .../Config/DefaultHttpClientConfiguration.swift | 5 ----- .../amazon/smithy/swift/codegen/SwiftWriter.kt | 4 ++-- .../swift/codegen/config/DefaultClientConfiguration.kt | 10 ---------- .../codegen/config/DefaultHttpClientConfiguration.kt | 10 ---------- 5 files changed, 2 insertions(+), 32 deletions(-) diff --git a/Sources/ClientRuntime/Config/DefaultClientConfiguration.swift b/Sources/ClientRuntime/Config/DefaultClientConfiguration.swift index 399878c9c..1fc8b4209 100644 --- a/Sources/ClientRuntime/Config/DefaultClientConfiguration.swift +++ b/Sources/ClientRuntime/Config/DefaultClientConfiguration.swift @@ -31,10 +31,5 @@ public protocol DefaultClientConfiguration: ClientConfiguration { /// If none is provided, only a default logger provider will be used. var telemetryProvider: TelemetryProvider { get set } - /// Adds an `InterceptorProvider` that will be used to provide interceptors for all operations. - /// - /// - Parameter provider: The `InterceptorProvider` to add. - func addInterceptorProvider(_ provider: InterceptorProvider) - /// TODO(plugins): Add Checksum, etc. } diff --git a/Sources/ClientRuntime/Config/DefaultHttpClientConfiguration.swift b/Sources/ClientRuntime/Config/DefaultHttpClientConfiguration.swift index 5b390a4e5..baa9a486d 100644 --- a/Sources/ClientRuntime/Config/DefaultHttpClientConfiguration.swift +++ b/Sources/ClientRuntime/Config/DefaultHttpClientConfiguration.swift @@ -35,9 +35,4 @@ public protocol DefaultHttpClientConfiguration: ClientConfiguration { /// /// Default resolver will look for the token in the `~/.aws/sso/cache` directory. var bearerTokenIdentityResolver: any BearerTokenIdentityResolver { get set } - - /// Adds a `HttpInterceptorProvider` that will be used to provide interceptors for all HTTP operations. - /// - /// - Parameter provider: The `HttpInterceptorProvider` to add. - func addInterceptorProvider(_ provider: HttpInterceptorProvider) } diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt index ed8bc8e06..46bcb83d9 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt @@ -106,6 +106,8 @@ class SwiftWriter( fun addImport(symbol: Symbol) { symbol.references.forEach { addImport(it.symbol) } + val additionalImports = symbol.getProperty("additionalImports").getOrElse { emptyList() } as List + additionalImports.forEach { addImport(it) } if (symbol.isBuiltIn || symbol.isServiceNestedNamespace || symbol.namespace.isEmpty()) return val spiNames = symbol.getProperty("spiNames").getOrElse { emptyList() } as List val decl = symbol.getProperty("decl").getOrNull()?.toString() @@ -127,8 +129,6 @@ class SwiftWriter( addImport(symbol.namespace, internalSPINames = spiNames) } symbol.dependencies.forEach { addDependency(it) } - val additionalImports = symbol.getProperty("additionalImports").getOrElse { emptyList() } as List - additionalImports.forEach { addImport(it) } } fun addImport( diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultClientConfiguration.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultClientConfiguration.kt index 39dce4895..6db6bf4e5 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultClientConfiguration.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultClientConfiguration.kt @@ -47,14 +47,4 @@ class DefaultClientConfiguration : ClientConfiguration { accessModifier = AccessModifier.PublicPrivateSet ) ) - - override fun getMethods(ctx: ProtocolGenerator.GenerationContext): Set = setOf( - Function( - name = "addInterceptorProvider", - renderBody = { writer -> writer.write("self.interceptorProviders.append(provider)") }, - parameters = listOf( - FunctionParameter.NoLabel("provider", ClientRuntimeTypes.Core.InterceptorProvider) - ), - ) - ) } diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultHttpClientConfiguration.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultHttpClientConfiguration.kt index d478e186f..556688e81 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultHttpClientConfiguration.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultHttpClientConfiguration.kt @@ -54,14 +54,4 @@ class DefaultHttpClientConfiguration : ClientConfiguration { { it.format("\$N(token: \$N(token: \"\"))", SmithyIdentityTypes.StaticBearerTokenIdentityResolver, SmithyIdentityTypes.BearerTokenIdentity) } ) ) - - override fun getMethods(ctx: ProtocolGenerator.GenerationContext): Set = setOf( - Function( - name = "addInterceptorProvider", - renderBody = { writer -> writer.write("self.httpInterceptorProviders.append(provider)") }, - parameters = listOf( - FunctionParameter.NoLabel("provider", ClientRuntimeTypes.Core.HttpInterceptorProvider) - ), - ) - ) } From 0f295467b66657661cb9f9c832f79c4551e77a99 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 5 Feb 2025 10:52:50 -0600 Subject: [PATCH 2/4] Fix tests and lint --- .../swift/codegen/config/DefaultClientConfiguration.kt | 2 -- .../codegen/config/DefaultHttpClientConfiguration.kt | 2 -- .../swift/codegen/HttpProtocolClientGeneratorTests.kt | 8 -------- 3 files changed, 12 deletions(-) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultClientConfiguration.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultClientConfiguration.kt index 6db6bf4e5..c7f5b8d8d 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultClientConfiguration.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultClientConfiguration.kt @@ -8,8 +8,6 @@ package software.amazon.smithy.swift.codegen.config import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator import software.amazon.smithy.swift.codegen.lang.AccessModifier -import software.amazon.smithy.swift.codegen.lang.Function -import software.amazon.smithy.swift.codegen.lang.FunctionParameter import software.amazon.smithy.swift.codegen.model.toOptional import software.amazon.smithy.swift.codegen.swiftmodules.ClientRuntimeTypes import software.amazon.smithy.swift.codegen.swiftmodules.SmithyRetriesAPITypes diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultHttpClientConfiguration.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultHttpClientConfiguration.kt index 556688e81..428941031 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultHttpClientConfiguration.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/DefaultHttpClientConfiguration.kt @@ -8,8 +8,6 @@ package software.amazon.smithy.swift.codegen.config import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator import software.amazon.smithy.swift.codegen.lang.AccessModifier -import software.amazon.smithy.swift.codegen.lang.Function -import software.amazon.smithy.swift.codegen.lang.FunctionParameter import software.amazon.smithy.swift.codegen.model.toGeneric import software.amazon.smithy.swift.codegen.model.toOptional import software.amazon.smithy.swift.codegen.swiftmodules.ClientRuntimeTypes diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt index a7ed9b185..575cbd75a 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt @@ -131,14 +131,6 @@ extension RestJsonProtocolClient { return "" } - public func addInterceptorProvider(_ provider: ClientRuntime.InterceptorProvider) { - self.interceptorProviders.append(provider) - } - - public func addInterceptorProvider(_ provider: ClientRuntime.HttpInterceptorProvider) { - self.httpInterceptorProviders.append(provider) - } - } public static func builder() -> ClientRuntime.ClientBuilder { From f2a66b19ec9577f2c1c05517d9f42d7bc78ef915 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 5 Feb 2025 11:23:06 -0600 Subject: [PATCH 3/4] Remove Function & FunctionParameter --- .../codegen/config/ClientConfiguration.kt | 6 --- .../smithy/swift/codegen/lang/Function.kt | 37 ------------------ .../swift/codegen/lang/FunctionParameter.kt | 39 ------------------- 3 files changed, 82 deletions(-) delete mode 100644 smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/Function.kt delete mode 100644 smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/FunctionParameter.kt diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/ClientConfiguration.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/ClientConfiguration.kt index 155c880f0..d7086c1de 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/ClientConfiguration.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/config/ClientConfiguration.kt @@ -8,7 +8,6 @@ package software.amazon.smithy.swift.codegen.config import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.swift.codegen.Dependency import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator -import software.amazon.smithy.swift.codegen.lang.Function import software.amazon.smithy.swift.codegen.model.buildSymbol /** @@ -22,11 +21,6 @@ interface ClientConfiguration { fun getProperties(ctx: ProtocolGenerator.GenerationContext): Set - /** - * The methods to render in the generated client configuration - */ - fun getMethods(ctx: ProtocolGenerator.GenerationContext): Set = setOf() - companion object { fun runtimeSymbol( name: String, diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/Function.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/Function.kt deleted file mode 100644 index 2e872f343..000000000 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/Function.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.swift.codegen.lang - -import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.swift.codegen.SwiftWriter -import java.util.function.Consumer - -/** - * Representation of a Swift function. - */ -data class Function( - val name: String, - val renderBody: Consumer, - val parameters: List = emptyList(), - val returnType: Symbol? = null, - val accessModifier: AccessModifier = AccessModifier.Public, - val isAsync: Boolean = false, - val isThrowing: Boolean = false, -) { - - /** - * Render this function using the given writer. - */ - fun render(writer: SwiftWriter) { - val renderedParameters = parameters.joinToString(", ") { it.rendered(writer) } - val renderedAsync = if (isAsync) "async " else "" - val renderedThrows = if (isThrowing) "throws " else "" - val renderedReturnType = returnType?.let { writer.format("-> \$N ", it) } ?: "" - writer.openBlock("${accessModifier.renderedRightPad()}func $name($renderedParameters) $renderedAsync$renderedThrows$renderedReturnType{", "}") { - renderBody.accept(writer) - } - } -} diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/FunctionParameter.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/FunctionParameter.kt deleted file mode 100644 index 787e047f8..000000000 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/lang/FunctionParameter.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.swift.codegen.lang - -import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.swift.codegen.SwiftWriter - -/** - * Representation of a Swift function parameter. - */ -sealed class FunctionParameter(val name: String, val type: Symbol) { - - /** - * Function parameter with no label, i.e. `_ foo: String` - */ - class NoLabel(name: String, type: Symbol) : FunctionParameter(name, type) - - /** - * Function parameter with the default label, i.e. `foo: String` - */ - class DefaultLabel(val label: String, type: Symbol) : FunctionParameter(label, type) - - /** - * Function parameter with a custom label, i.e. `foo bar: String` - */ - class CustomLabel(val label: String, name: String, type: Symbol) : FunctionParameter(name, type) - - /** - * Creates a string representation of this function parameter. - */ - fun rendered(writer: SwiftWriter): String = when (this) { - is NoLabel -> writer.format("_ $name: \$N", type) - is DefaultLabel -> writer.format("$label: \$N", type) - is CustomLabel -> writer.format("$label $name: \$N", type) - } -} From ee3eb9e32122c9ac085ce38328dff3ddb7a026b6 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 5 Feb 2025 11:27:58 -0600 Subject: [PATCH 4/4] Fix codegen build --- .../codegen/integration/HttpProtocolServiceClient.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt index 47e17dee7..6f489f17b 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt @@ -136,14 +136,6 @@ open class HttpProtocolServiceClient( renderCustomConfigInitializer(properties) renderPartitionID() - - clientConfigs - .flatMap { it.getMethods(ctx) } - .sortedBy { it.accessModifier } - .forEach { - it.render(writer) - writer.write("") - } } writer.write("") }