diff --git a/Sources/Core/AWSClientRuntime/Middlewares/Sha256TreeHashMiddleware.swift b/Sources/Core/AWSClientRuntime/Middlewares/Sha256TreeHashMiddleware.swift index 441dbb368ed..ffb16647072 100644 --- a/Sources/Core/AWSClientRuntime/Middlewares/Sha256TreeHashMiddleware.swift +++ b/Sources/Core/AWSClientRuntime/Middlewares/Sha256TreeHashMiddleware.swift @@ -5,8 +5,7 @@ import AwsCommonRuntimeKit import ClientRuntime import AwsCCal -public struct Sha256TreeHashMiddleware: Middleware { +public struct Sha256TreeHashMiddleware: Middleware { public let id: String = "Sha256TreeHash" private let X_AMZ_SHA256_TREE_HASH_HEADER_NAME = "X-Amz-Sha256-Tree-Hash" @@ -104,5 +103,4 @@ public struct Sha256TreeHashMiddleware public typealias Context = HttpContext - public typealias MError = OperationStackError } diff --git a/Sources/Core/AWSClientRuntime/Middlewares/SigV4Middleware.swift b/Sources/Core/AWSClientRuntime/Middlewares/SigV4Middleware.swift index ca3ad668d80..879dcee9883 100644 --- a/Sources/Core/AWSClientRuntime/Middlewares/SigV4Middleware.swift +++ b/Sources/Core/AWSClientRuntime/Middlewares/SigV4Middleware.swift @@ -6,8 +6,7 @@ import ClientRuntime import AwsCommonRuntimeKit -public struct SigV4Middleware: Middleware { +public struct SigV4Middleware: Middleware { public let id: String = "Sigv4Signer" let config: SigV4Config diff --git a/Sources/Core/AWSClientRuntime/Middlewares/UserAgentMiddleware.swift b/Sources/Core/AWSClientRuntime/Middlewares/UserAgentMiddleware.swift index a9c85a72754..0c8b3421aaf 100644 --- a/Sources/Core/AWSClientRuntime/Middlewares/UserAgentMiddleware.swift +++ b/Sources/Core/AWSClientRuntime/Middlewares/UserAgentMiddleware.swift @@ -7,7 +7,7 @@ import ClientRuntime -public struct UserAgentMiddleware: Middleware { +public struct UserAgentMiddleware: Middleware { public let id: String = "UserAgentHeader" private let X_AMZ_USER_AGENT: String = "x-amz-user-agent" diff --git a/Sources/Core/AWSClientRuntime/Middlewares/XAmzTargetMiddleware.swift b/Sources/Core/AWSClientRuntime/Middlewares/XAmzTargetMiddleware.swift index 06d2ef8346e..0f0df06ef1c 100644 --- a/Sources/Core/AWSClientRuntime/Middlewares/XAmzTargetMiddleware.swift +++ b/Sources/Core/AWSClientRuntime/Middlewares/XAmzTargetMiddleware.swift @@ -2,8 +2,7 @@ // SPDX-License-Identifier: Apache-2.0. import ClientRuntime -public struct XAmzTargetMiddleware: Middleware { +public struct XAmzTargetMiddleware: Middleware { public let id: String = "XAmzTargetHeader" let xAmzTarget: String diff --git a/Tests/Core/AWSClientRuntimeTests/Middlewares/Sha256TreeHashMiddlewareTests.swift b/Tests/Core/AWSClientRuntimeTests/Middlewares/Sha256TreeHashMiddlewareTests.swift index 03acedba54c..f5f4385d78f 100644 --- a/Tests/Core/AWSClientRuntimeTests/Middlewares/Sha256TreeHashMiddlewareTests.swift +++ b/Tests/Core/AWSClientRuntimeTests/Middlewares/Sha256TreeHashMiddlewareTests.swift @@ -20,12 +20,12 @@ class Sha256TreeHashMiddlewareTests: XCTestCase { let byteArray: [UInt8] = Array(repeating: 0, count: bytesIn5_5MB) let byteStream = ByteStream.stream(BufferedStream(data: .init(byteArray), isClosed: true)) let streamInput = MockStreamInput(body: byteStream) - var stack = OperationStack(id: "TreeHashMiddlewareTestStack") + var stack = OperationStack(id: "TreeHashMiddlewareTestStack") stack.serializeStep.intercept(position: .before, middleware: MockSerializeStreamMiddleware()) let mockHttpResponse = HttpResponse(body: HttpBody.none, statusCode: .accepted) let mockOutput = try MockOutput(httpResponse: mockHttpResponse, decoder: nil) let output = OperationOutput(httpResponse: mockHttpResponse, output: mockOutput) - stack.finalizeStep.intercept(position: .after, middleware: Sha256TreeHashMiddleware()) + stack.finalizeStep.intercept(position: .after, middleware: Sha256TreeHashMiddleware()) _ = try await stack.handleMiddleware(context: context, input: streamInput, next: MockHandler(handleCallback: { context, input in let linear = input.headers.value(for: "X-Amz-Content-Sha256") XCTAssertEqual(linear, "733cf513448ce6b20ad1bc5e50eb27c06aefae0c320713a5dd99f4e51bc1ca60") diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGenerator.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGenerator.kt index 50fc7f398cc..9f50c05d763 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGenerator.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGenerator.kt @@ -45,9 +45,10 @@ class PresignerGenerator : SwiftIntegration { presignOperations.forEach { presignableOperation -> val op = ctx.model.expectShape(presignableOperation.operationId) val inputType = op.input.get().getName() + val outputType = op.output.get().getName() delegator.useFileWriter("${ctx.settings.moduleName}/models/$inputType+Presigner.swift") { writer -> var serviceConfig = AWSServiceConfig(writer, protoCtx) - renderPresigner(writer, ctx, delegator, op, inputType, serviceConfig) + renderPresigner(writer, ctx, delegator, op, inputType, outputType, serviceConfig) } // Expose presign-request as a method for service client object val symbol = protoCtx.symbolProvider.toSymbol(protoCtx.service) @@ -71,6 +72,7 @@ class PresignerGenerator : SwiftIntegration { delegator: SwiftDelegator, op: OperationShape, inputType: String, + outputType: String, serviceConfig: AWSServiceConfig ) { val serviceShape = ctx.model.expectShape(ctx.settings.service) @@ -108,7 +110,11 @@ class PresignerGenerator : SwiftIntegration { } val requestBuilderName = "presignedRequestBuilder" val builtRequestName = "builtRequest" - writer.write("let $requestBuilderName = try await $operationStackName.presignedRequest(context: context, input: input, next: \$N())", NoopHandler) + writer.write( + "let $requestBuilderName = try await $operationStackName.presignedRequest(context: context, input: input, output: \$L(), next: \$N())", + outputType, + NoopHandler + ) writer.openBlock("guard let $builtRequestName = $requestBuilderName?.build() else {", "}") { writer.write("return nil") } diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/presignable/PresignableUrlIntegration.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/presignable/PresignableUrlIntegration.kt index 63fc4f3eac2..aaaa11f16bc 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/presignable/PresignableUrlIntegration.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/presignable/PresignableUrlIntegration.kt @@ -67,9 +67,10 @@ class PresignableUrlIntegration(private val presignedOperations: Map val op = ctx.model.expectShape(presignableOperation.operationId) val inputType = op.input.get().getName() + val outputType = op.output.get().getName() delegator.useFileWriter("${ctx.settings.moduleName}/models/$inputType+Presigner.swift") { writer -> val serviceConfig = AWSServiceConfig(writer, protocolGenerationContext) - renderPresigner(writer, ctx, delegator, op, inputType, serviceConfig) + renderPresigner(writer, ctx, delegator, op, inputType, outputType, serviceConfig) } // Expose presign-URL as a method for service client object val symbol = protocolGenerationContext.symbolProvider.toSymbol(protocolGenerationContext.service) @@ -93,6 +94,7 @@ class PresignableUrlIntegration(private val presignedOperations: Map(ctx.settings.service) @@ -139,7 +141,8 @@ class PresignableUrlIntegration(private val presignedOperations: Map(config: sigv4Config))", - AWSClientRuntimeTypes.Signing.SigV4Middleware, output, outputError + "$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: \$N<\$N>(config: sigv4Config))", + AWSClientRuntimeTypes.Signing.SigV4Middleware, + output ) } diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/EndpointResolverMiddleware.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/EndpointResolverMiddleware.kt index 113fe714585..7b1039d9af1 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/EndpointResolverMiddleware.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/EndpointResolverMiddleware.kt @@ -12,7 +12,6 @@ import software.amazon.smithy.aws.swift.codegen.AWSSwiftDependency import software.amazon.smithy.aws.swift.codegen.ENDPOINT_PARAMS import software.amazon.smithy.aws.swift.codegen.ENDPOINT_RESOLVER import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.swift.codegen.ClientRuntimeTypes import software.amazon.smithy.swift.codegen.Middleware import software.amazon.smithy.swift.codegen.SwiftDependency import software.amazon.smithy.swift.codegen.SwiftWriter @@ -30,8 +29,7 @@ class EndpointResolverMiddleware( override val id: String = "EndpointResolverMiddleware" - override val typeName = - "EndpointResolverMiddleware<$outputSymbol: ${ClientRuntimeTypes.Http.HttpResponseBinding}, $outputErrorSymbol: ${ClientRuntimeTypes.Http.HttpResponseErrorBinding}>" + override val typeName = "EndpointResolverMiddleware<$outputSymbol>" override val properties: MutableMap = mutableMapOf( ENDPOINT_RESOLVER to AWSServiceTypes.EndpointResolver, diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/GlacierAccountIdMiddleware.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/GlacierAccountIdMiddleware.kt index 813c6a6475a..76d5c4b5428 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/GlacierAccountIdMiddleware.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/GlacierAccountIdMiddleware.kt @@ -22,7 +22,6 @@ class GlacierAccountIdMiddleware(private val model: Model, private val symbolPro override fun render(ctx: ProtocolGenerator.GenerationContext, writer: SwiftWriter, op: OperationShape, operationStackName: String) { val outputShapeName = MiddlewareShapeUtils.outputSymbol(symbolProvider, model, op).name - val outputErrorShapeName = MiddlewareShapeUtils.outputErrorSymbolName(op) val accountId = model.expectShape(op.input.get()).members().first { it.memberName.lowercase() == "accountid" } writer.openBlock( "$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, id: \"${name}\") { (context, input, next) -> \$N<$outputShapeName> in", "}", diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/OperationEndpointResolverMiddleware.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/OperationEndpointResolverMiddleware.kt index dbd62a38826..cf4fbcfeb35 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/OperationEndpointResolverMiddleware.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/OperationEndpointResolverMiddleware.kt @@ -71,7 +71,7 @@ class OperationEndpointResolverMiddleware( } writer.write("let endpointParams = EndpointParams(${params.joinToString(separator = ", ")})") val middlewareParamsString = "endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams" - writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: \$N<\$N, \$N>($middlewareParamsString))", AWSServiceTypes.EndpointResolverMiddleware, output, outputError) + writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: \$N<\$N>($middlewareParamsString))", AWSServiceTypes.EndpointResolverMiddleware, output) } /** diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/Sha256TreeHashMiddleware.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/Sha256TreeHashMiddleware.kt index e8868b9f67e..c74222afa2f 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/Sha256TreeHashMiddleware.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/Sha256TreeHashMiddleware.kt @@ -20,7 +20,6 @@ class Sha256TreeHashMiddleware(private val symbolProvider: SymbolProvider, priva override fun render(ctx: ProtocolGenerator.GenerationContext, writer: SwiftWriter, op: OperationShape, operationStackName: String) { val outputShape = MiddlewareShapeUtils.outputSymbol(symbolProvider, model, op) - val outputErrorShapeName = MiddlewareShapeUtils.outputErrorSymbolName(op) - writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: \$N<\$N, $outputErrorShapeName>())", AWSClientRuntimeTypes.Core.Sha256TreeHashMiddleware, outputShape) + writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: \$N<\$N>())", AWSClientRuntimeTypes.Core.Sha256TreeHashMiddleware, outputShape) } } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/AWSSigningMiddlewareTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/AWSSigningMiddlewareTests.kt index 6200e8138dc..181200f25ef 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/AWSSigningMiddlewareTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/AWSSigningMiddlewareTests.kt @@ -77,9 +77,9 @@ class AWSSigningMiddlewareTests { @Test fun `render unsignedBody true`() { val expectedContents = """ - let sigv4Config = AWSClientRuntime.SigV4Config(unsignedBody: true, signingAlgorithm: .sigv4) - stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """.trimIndent() +let sigv4Config = AWSClientRuntime.SigV4Config(unsignedBody: true, signingAlgorithm: .sigv4) +stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" val writer = SwiftWriter("testName") val context = contextForSDK("ExampleService") val operation = context.model.operationShapes.first() @@ -102,9 +102,9 @@ class AWSSigningMiddlewareTests { @Test fun `render unsignedBody false`() { val expectedContents = """ - let sigv4Config = AWSClientRuntime.SigV4Config(unsignedBody: false, signingAlgorithm: .sigv4) - stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """.trimIndent() +let sigv4Config = AWSClientRuntime.SigV4Config(unsignedBody: false, signingAlgorithm: .sigv4) +stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" val writer = SwiftWriter("testName") val context = contextForSDK("ExampleService") val operation = context.model.operationShapes.first() @@ -127,9 +127,9 @@ class AWSSigningMiddlewareTests { @Test fun `render unsignedBody true, presigner`() { val expectedContents = """ - let sigv4Config = AWSClientRuntime.SigV4Config(expiration: expiration, unsignedBody: true, signingAlgorithm: .sigv4) - stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """.trimIndent() +let sigv4Config = AWSClientRuntime.SigV4Config(expiration: expiration, unsignedBody: true, signingAlgorithm: .sigv4) +stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" val writer = SwiftWriter("testName") val context = contextForSDK("ExampleService") val operation = context.model.operationShapes.first() @@ -152,9 +152,9 @@ class AWSSigningMiddlewareTests { @Test fun `render unsignedBody false, presigner`() { val expectedContents = """ - let sigv4Config = AWSClientRuntime.SigV4Config(expiration: expiration, unsignedBody: false, signingAlgorithm: .sigv4) - stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """.trimIndent() +let sigv4Config = AWSClientRuntime.SigV4Config(expiration: expiration, unsignedBody: false, signingAlgorithm: .sigv4) +stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" val writer = SwiftWriter("testName") val context = contextForSDK("ExampleService") val operation = context.model.operationShapes.first() @@ -177,9 +177,9 @@ class AWSSigningMiddlewareTests { @Test fun `render s3 with query string sig`() { val expectedContents = """ - let sigv4Config = AWSClientRuntime.SigV4Config(signatureType: .requestQueryParams, useDoubleURIEncode: false, shouldNormalizeURIPath: false, expiration: expiration, unsignedBody: true, signingAlgorithm: .sigv4) - stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """.trimIndent() +let sigv4Config = AWSClientRuntime.SigV4Config(signatureType: .requestQueryParams, useDoubleURIEncode: false, shouldNormalizeURIPath: false, expiration: expiration, unsignedBody: true, signingAlgorithm: .sigv4) +stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" val writer = SwiftWriter("testName") val context = contextForSDK("S3") val operation = context.model.operationShapes.first() @@ -202,8 +202,8 @@ class AWSSigningMiddlewareTests { @Test fun `render s3 with signed body & normal sig`() { val expectedContents = """ - let sigv4Config = AWSClientRuntime.SigV4Config(useDoubleURIEncode: false, shouldNormalizeURIPath: false, expiration: expiration, signedBodyHeader: .contentSha256, unsignedBody: false, signingAlgorithm: .sigv4) - stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +let sigv4Config = AWSClientRuntime.SigV4Config(useDoubleURIEncode: false, shouldNormalizeURIPath: false, expiration: expiration, signedBodyHeader: .contentSha256, unsignedBody: false, signingAlgorithm: .sigv4) +stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) """.trimIndent() val writer = SwiftWriter("testName") val context = contextForSDK("S3") @@ -227,9 +227,9 @@ class AWSSigningMiddlewareTests { @Test fun `render glacier with signed body & normal sig`() { val expectedContents = """ - let sigv4Config = AWSClientRuntime.SigV4Config(signedBodyHeader: .contentSha256, unsignedBody: false, signingAlgorithm: .sigv4) - stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """.trimIndent() +let sigv4Config = AWSClientRuntime.SigV4Config(signedBodyHeader: .contentSha256, unsignedBody: false, signingAlgorithm: .sigv4) +stack.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" val writer = SwiftWriter("testName") val context = contextForSDK("Glacier") val operation = context.model.operationShapes.first() diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverMiddlewareTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverMiddlewareTests.kt index acfe667a880..7c586781054 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverMiddlewareTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverMiddlewareTests.kt @@ -25,91 +25,91 @@ class EndpointResolverMiddlewareTests { MiddlewareGenerator(writer, middleware).generate() val contents = writer.toString() val expected = """ - public struct EndpointResolverMiddleware: ClientRuntime.Middleware { - public let id: Swift.String = "EndpointResolverMiddleware" - - let endpointResolver: EndpointResolver - - let endpointParams: EndpointParams - - let authSchemeResolver: AWSClientRuntime.AuthSchemeResolver - - public init(endpointResolver: EndpointResolver, endpointParams: EndpointParams, authSchemeResolver: AWSClientRuntime.AuthSchemeResolver = AWSClientRuntime.DefaultAuthSchemeResolver()) { - self.endpointResolver = endpointResolver - self.endpointParams = endpointParams - self.authSchemeResolver = authSchemeResolver - } - - public func handle(context: Context, - input: ClientRuntime.SdkHttpRequestBuilder, - next: H) async throws -> ClientRuntime.OperationOutput - where H: Handler, - Self.MInput == H.Input, - Self.MOutput == H.Output, - Self.Context == H.Context - { - let endpoint = try endpointResolver.resolve(params: endpointParams) - - var signingName: String? = nil - var signingRegion: String? = nil - var signingAlgorithm: String? = nil - if let authSchemes = endpoint.authSchemes() { - let schemes = try authSchemes.map { try AuthScheme(from: ${'$'}0) } - let authScheme = try authSchemeResolver.resolve(authSchemes: schemes) - signingAlgorithm = authScheme.name - switch authScheme { - case .sigV4(let param): - signingName = param.signingName - signingRegion = param.signingRegion - case .sigV4A(let param): - signingName = param.signingName - signingRegion = param.signingRegionSet?.first - case .none: - break - } - } - - let awsEndpoint = AWSEndpoint(endpoint: endpoint, signingName: signingName, signingRegion: signingRegion) - - var host = "" - if let hostOverride = context.getHost() { - host = hostOverride - } else { - host = "\(context.getHostPrefix() ?? "")\(awsEndpoint.endpoint.host)" - } - - if let protocolType = awsEndpoint.endpoint.protocolType { - input.withProtocol(protocolType) - } - - if let signingRegion = signingRegion { - context.attributes.set(key: HttpContext.signingRegion, value: signingRegion) - } - if let signingName = signingName { - context.attributes.set(key: HttpContext.signingName, value: signingName) - } - if let signingAlgorithm = signingAlgorithm { - context.attributes.set(key: HttpContext.signingAlgorithm, value: signingAlgorithm) - } - - if let headers = endpoint.headers { - input.withHeaders(headers) - } - - input.withMethod(context.getMethod()) - .withHost(host) - .withPort(awsEndpoint.endpoint.port) - .withPath(awsEndpoint.endpoint.path.appendingPathComponent(context.getPath())) - .withHeader(name: "Host", value: host) - - return try await next.handle(context: context, input: input) - } - - public typealias MInput = ClientRuntime.SdkHttpRequestBuilder - public typealias MOutput = ClientRuntime.OperationOutput - public typealias Context = ClientRuntime.HttpContext +public struct EndpointResolverMiddleware: ClientRuntime.Middleware { + public let id: Swift.String = "EndpointResolverMiddleware" + + let endpointResolver: EndpointResolver + + let endpointParams: EndpointParams + + let authSchemeResolver: AWSClientRuntime.AuthSchemeResolver + + public init(endpointResolver: EndpointResolver, endpointParams: EndpointParams, authSchemeResolver: AWSClientRuntime.AuthSchemeResolver = AWSClientRuntime.DefaultAuthSchemeResolver()) { + self.endpointResolver = endpointResolver + self.endpointParams = endpointParams + self.authSchemeResolver = authSchemeResolver + } + + public func handle(context: Context, + input: ClientRuntime.SdkHttpRequestBuilder, + next: H) async throws -> ClientRuntime.OperationOutput + where H: Handler, + Self.MInput == H.Input, + Self.MOutput == H.Output, + Self.Context == H.Context + { + let endpoint = try endpointResolver.resolve(params: endpointParams) + + var signingName: String? = nil + var signingRegion: String? = nil + var signingAlgorithm: String? = nil + if let authSchemes = endpoint.authSchemes() { + let schemes = try authSchemes.map { try AuthScheme(from: ${'$'}0) } + let authScheme = try authSchemeResolver.resolve(authSchemes: schemes) + signingAlgorithm = authScheme.name + switch authScheme { + case .sigV4(let param): + signingName = param.signingName + signingRegion = param.signingRegion + case .sigV4A(let param): + signingName = param.signingName + signingRegion = param.signingRegionSet?.first + case .none: + break } - """.trimIndent() + } + + let awsEndpoint = AWSEndpoint(endpoint: endpoint, signingName: signingName, signingRegion: signingRegion) + + var host = "" + if let hostOverride = context.getHost() { + host = hostOverride + } else { + host = "\(context.getHostPrefix() ?? "")\(awsEndpoint.endpoint.host)" + } + + if let protocolType = awsEndpoint.endpoint.protocolType { + input.withProtocol(protocolType) + } + + if let signingRegion = signingRegion { + context.attributes.set(key: HttpContext.signingRegion, value: signingRegion) + } + if let signingName = signingName { + context.attributes.set(key: HttpContext.signingName, value: signingName) + } + if let signingAlgorithm = signingAlgorithm { + context.attributes.set(key: HttpContext.signingAlgorithm, value: signingAlgorithm) + } + + if let headers = endpoint.headers { + input.withHeaders(headers) + } + + input.withMethod(context.getMethod()) + .withHost(host) + .withPort(awsEndpoint.endpoint.port) + .withPath(awsEndpoint.endpoint.path.appendingPathComponent(context.getPath())) + .withHeader(name: "Host", value: host) + + return try await next.handle(context: context, input: input) + } + + public typealias MInput = ClientRuntime.SdkHttpRequestBuilder + public typealias MOutput = ClientRuntime.OperationOutput + public typealias Context = ClientRuntime.HttpContext +} +""" contents.shouldContainOnlyOnce(expected) } } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EventStreamTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EventStreamTests.kt index ca768938afb..88d4b80b7bc 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EventStreamTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EventStreamTests.kt @@ -190,7 +190,6 @@ extension EventStreamTestClientTypes.TestStream: ClientRuntime.MessageUnmarshall var expected = """ public func testStreamOp(input: TestStreamOpInput) async throws -> TestStreamOpOutput { - let encoder = self.encoder let context = ClientRuntime.HttpContextBuilder() .withEncoder(value: encoder) .withDecoder(value: decoder) @@ -206,20 +205,20 @@ extension EventStreamTestClientTypes.TestStream: ClientRuntime.MessageUnmarshall .withSigningRegion(value: config.signingRegion) .build() try context.setupBidirectionalStreaming() - var operation = ClientRuntime.OperationStack(id: "testStreamOp") - operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) + var operation = ClientRuntime.OperationStack(id: "testStreamOp") + operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware()) let endpointParams = EndpointParams() - operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) + operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) operation.buildStep.intercept(position: .before, middleware: AWSClientRuntime.UserAgentMiddleware(metadata: AWSClientRuntime.AWSUserAgentMetadata.fromConfig(serviceID: serviceName, version: "1.0.0", config: config))) operation.serializeStep.intercept(position: .after, middleware: ContentTypeMiddleware(contentType: "application/json")) operation.serializeStep.intercept(position: .after, middleware: ClientRuntime.EventStreamBodyMiddleware(keyPath: \.value, defaultBody: "{}")) operation.finalizeStep.intercept(position: .before, middleware: ClientRuntime.ContentLengthMiddleware()) - operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) + operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) let sigv4Config = AWSClientRuntime.SigV4Config(unsignedBody: false, signingAlgorithm: .sigv4) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware()) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) + operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware(responseClosure(decoder: decoder), responseErrorClosure(TestStreamOpOutputError.self, decoder: decoder))) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) let result = try await operation.handleMiddleware(context: context, input: input, next: client.getHandler()) return result } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/OperationEndpointResolverMiddlewareTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/OperationEndpointResolverMiddlewareTests.kt index 4165e4fe99e..85e361186d2 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/OperationEndpointResolverMiddlewareTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/OperationEndpointResolverMiddlewareTests.kt @@ -22,12 +22,12 @@ class OperationEndpointResolverMiddlewareTests { middleware.render(context, writer, operation, "operationStack") var contents = writer.toString() val expected = """ - guard let region = config.region else { - throw SdkError.client(ClientError.unknownError(("Missing required parameter: region"))) - } - let endpointParams = EndpointParams(boolBar: true, boolBaz: input.fuzz, boolFoo: config.serviceSpecific.boolFoo, endpoint: config.endpoint, region: region, stringBar: "some value", stringBaz: input.buzz, stringFoo: config.serviceSpecific.stringFoo) - operationStack.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) - """.trimIndent() +guard let region = config.region else { + throw SdkError.client(ClientError.unknownError(("Missing required parameter: region"))) +} +let endpointParams = EndpointParams(boolBar: true, boolBaz: input.fuzz, boolFoo: config.serviceSpecific.boolFoo, endpoint: config.endpoint, region: region, stringBar: "some value", stringBaz: input.buzz, stringFoo: config.serviceSpecific.stringFoo) +operationStack.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) +""" contents.shouldContainOnlyOnce(expected) } } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGeneratorTests.kt index a01719ef2f8..9b12ff1a132 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGeneratorTests.kt @@ -15,10 +15,6 @@ class PresignerGeneratorTests { val contents = TestContextGenerator.getFileContents(context.manifest, "/Example/models/GetFooInput+Presigner.swift") contents.shouldSyntacticSanityCheck() val expectedContents = """ -import AWSClientRuntime -import ClientRuntime -import typealias Foundation.TimeInterval - extension GetFooInput { public func presign(config: ExampleClient.ExampleClientConfiguration, expiration: Foundation.TimeInterval) async throws -> ClientRuntime.SdkHttpRequest? { let serviceName = "example" @@ -43,18 +39,18 @@ extension GetFooInput { .withSigningName(value: "example-signing-name") .withSigningRegion(value: config.signingRegion) .build() - var operation = ClientRuntime.OperationStack(id: "getFoo") - operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) + var operation = ClientRuntime.OperationStack(id: "getFoo") + operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware()) let endpointParams = EndpointParams() - operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) + operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) operation.buildStep.intercept(position: .before, middleware: AWSClientRuntime.UserAgentMiddleware(metadata: AWSClientRuntime.AWSUserAgentMetadata.fromConfig(serviceID: serviceName, version: "1.0.0", config: config))) - operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) + operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) let sigv4Config = AWSClientRuntime.SigV4Config(expiration: expiration, unsignedBody: false, signingAlgorithm: .sigv4) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware()) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) - let presignedRequestBuilder = try await operation.presignedRequest(context: context, input: input, next: ClientRuntime.NoopHandler()) + operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware(responseClosure(decoder: decoder), responseErrorClosure(GetFooOutputError.self, decoder: decoder))) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) + let presignedRequestBuilder = try await operation.presignedRequest(context: context, input: input, output: GetFooOutput(), next: ClientRuntime.NoopHandler()) guard let builtRequest = presignedRequestBuilder?.build() else { return nil } @@ -95,21 +91,21 @@ extension PostFooInput { .withSigningName(value: "example-signing-name") .withSigningRegion(value: config.signingRegion) .build() - var operation = ClientRuntime.OperationStack(id: "postFoo") - operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) + var operation = ClientRuntime.OperationStack(id: "postFoo") + operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware()) let endpointParams = EndpointParams() - operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) + operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) operation.buildStep.intercept(position: .before, middleware: AWSClientRuntime.UserAgentMiddleware(metadata: AWSClientRuntime.AWSUserAgentMetadata.fromConfig(serviceID: serviceName, version: "1.0.0", config: config))) operation.serializeStep.intercept(position: .after, middleware: ContentTypeMiddleware(contentType: "application/json")) operation.serializeStep.intercept(position: .after, middleware: ClientRuntime.BodyMiddleware(documentWritingClosure: ClientRuntime.JSONReadWrite.documentWritingClosure(encoder: encoder), inputWritingClosure: JSONReadWrite.writingClosure())) operation.finalizeStep.intercept(position: .before, middleware: ClientRuntime.ContentLengthMiddleware()) - operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) + operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) let sigv4Config = AWSClientRuntime.SigV4Config(expiration: expiration, unsignedBody: false, signingAlgorithm: .sigv4) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware()) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) - let presignedRequestBuilder = try await operation.presignedRequest(context: context, input: input, next: ClientRuntime.NoopHandler()) + operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware(responseClosure(decoder: decoder), responseErrorClosure(PostFooOutputError.self, decoder: decoder))) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) + let presignedRequestBuilder = try await operation.presignedRequest(context: context, input: input, output: PostFooOutput(), next: ClientRuntime.NoopHandler()) guard let builtRequest = presignedRequestBuilder?.build() else { return nil } @@ -150,21 +146,21 @@ extension PutFooInput { .withSigningName(value: "example-signing-name") .withSigningRegion(value: config.signingRegion) .build() - var operation = ClientRuntime.OperationStack(id: "putFoo") - operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) + var operation = ClientRuntime.OperationStack(id: "putFoo") + operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware()) let endpointParams = EndpointParams() - operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) + operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) operation.buildStep.intercept(position: .before, middleware: AWSClientRuntime.UserAgentMiddleware(metadata: AWSClientRuntime.AWSUserAgentMetadata.fromConfig(serviceID: serviceName, version: "1.0.0", config: config))) operation.serializeStep.intercept(position: .after, middleware: ContentTypeMiddleware(contentType: "application/json")) operation.serializeStep.intercept(position: .after, middleware: ClientRuntime.BodyMiddleware(documentWritingClosure: ClientRuntime.JSONReadWrite.documentWritingClosure(encoder: encoder), inputWritingClosure: JSONReadWrite.writingClosure())) operation.finalizeStep.intercept(position: .before, middleware: ClientRuntime.ContentLengthMiddleware()) - operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) + operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) let sigv4Config = AWSClientRuntime.SigV4Config(expiration: expiration, unsignedBody: false, signingAlgorithm: .sigv4) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware()) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) - let presignedRequestBuilder = try await operation.presignedRequest(context: context, input: input, next: ClientRuntime.NoopHandler()) + operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware(responseClosure(decoder: decoder), responseErrorClosure(PutFooOutputError.self, decoder: decoder))) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) + let presignedRequestBuilder = try await operation.presignedRequest(context: context, input: input, output: PutFooOutput(), next: ClientRuntime.NoopHandler()) guard let builtRequest = presignedRequestBuilder?.build() else { return nil } @@ -205,21 +201,21 @@ extension PutObjectInput { .withSigningName(value: "s3") .withSigningRegion(value: config.signingRegion) .build() - var operation = ClientRuntime.OperationStack(id: "putObject") - operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) + var operation = ClientRuntime.OperationStack(id: "putObject") + operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware()) let endpointParams = EndpointParams() - operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) + operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) operation.buildStep.intercept(position: .before, middleware: AWSClientRuntime.UserAgentMiddleware(metadata: AWSClientRuntime.AWSUserAgentMetadata.fromConfig(serviceID: serviceName, version: "1.0.0", config: config))) operation.serializeStep.intercept(position: .after, middleware: ContentTypeMiddleware(contentType: "application/json")) operation.serializeStep.intercept(position: .after, middleware: ClientRuntime.BodyMiddleware(documentWritingClosure: SmithyXML.XMLReadWrite.documentWritingClosure(rootNodeInfo: .init("PutObjectInput")), inputWritingClosure: PutObjectInput.writingClosure(_:to:))) operation.finalizeStep.intercept(position: .before, middleware: ClientRuntime.ContentLengthMiddleware()) - operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) + operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) let sigv4Config = AWSClientRuntime.SigV4Config(useDoubleURIEncode: false, shouldNormalizeURIPath: false, expiration: expiration, signedBodyHeader: .contentSha256, unsignedBody: false, signingAlgorithm: .sigv4) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware()) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) - let presignedRequestBuilder = try await operation.presignedRequest(context: context, input: input, next: ClientRuntime.NoopHandler()) + operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware(responseClosure(decoder: decoder), responseErrorClosure(PutObjectOutputError.self, decoder: decoder))) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) + let presignedRequestBuilder = try await operation.presignedRequest(context: context, input: input, output: PutObjectOutput(), next: ClientRuntime.NoopHandler()) guard let builtRequest = presignedRequestBuilder?.build() else { return nil } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsquery/AWSQueryOperationStackTest.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsquery/AWSQueryOperationStackTest.kt index 827550e295c..89e3bb32b0e 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsquery/AWSQueryOperationStackTest.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsquery/AWSQueryOperationStackTest.kt @@ -22,7 +22,6 @@ class AWSQueryOperationStackTest { val expectedContents = """ public func noInputAndOutput(input: NoInputAndOutputInput) async throws -> NoInputAndOutputOutput { - let encoder = self.encoder let context = ClientRuntime.HttpContextBuilder() .withEncoder(value: encoder) .withDecoder(value: decoder) @@ -35,18 +34,18 @@ class AWSQueryOperationStackTest { .withCredentialsProvider(value: config.credentialsProvider) .withRegion(value: config.region) .build() - var operation = ClientRuntime.OperationStack(id: "noInputAndOutput") - operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) + var operation = ClientRuntime.OperationStack(id: "noInputAndOutput") + operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware()) let endpointParams = EndpointParams() - operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) + operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams)) operation.buildStep.intercept(position: .before, middleware: AWSClientRuntime.UserAgentMiddleware(metadata: AWSClientRuntime.AWSUserAgentMetadata.fromConfig(serviceID: serviceName, version: "1.0.0", config: config))) operation.serializeStep.intercept(position: .after, middleware: ClientRuntime.BodyMiddleware(documentWritingClosure: ClientRuntime.FormURLReadWrite.documentWritingClosure(encoder: encoder), inputWritingClosure: FormURLReadWrite.writingClosure())) operation.serializeStep.intercept(position: .after, middleware: ContentTypeMiddleware(contentType: "application/x-www-form-urlencoded")) operation.finalizeStep.intercept(position: .before, middleware: ClientRuntime.ContentLengthMiddleware()) - operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware()) - operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) + operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware(responseClosure(decoder: decoder), responseErrorClosure(NoInputAndOutputOutputError.self, decoder: decoder))) + operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) let result = try await operation.handleMiddleware(context: context, input: input, next: client.getHandler()) return result } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/PresignableUrlIntegrationTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/PresignableUrlIntegrationTests.kt index 8df7fec721e..eaf810f68db 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/PresignableUrlIntegrationTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/PresignableUrlIntegrationTests.kt @@ -21,8 +21,8 @@ class PresignableUrlIntegrationTests { contents.shouldSyntacticSanityCheck() val expectedContents = """ let sigv4Config = AWSClientRuntime.SigV4Config(signatureType: .requestQueryParams, expiration: expiration, unsignedBody: false, signingAlgorithm: .sigv4) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """ + operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" contents.shouldContainOnlyOnce(expectedContents) } @@ -33,8 +33,8 @@ class PresignableUrlIntegrationTests { contents.shouldSyntacticSanityCheck() val expectedContents = """ let sigv4Config = AWSClientRuntime.SigV4Config(signatureType: .requestQueryParams, useDoubleURIEncode: false, shouldNormalizeURIPath: false, expiration: expiration, unsignedBody: true, signingAlgorithm: .sigv4) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """ + operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" contents.shouldContainOnlyOnce(expectedContents) } @@ -45,8 +45,8 @@ class PresignableUrlIntegrationTests { contents.shouldSyntacticSanityCheck() val expectedContents = """ let sigv4Config = AWSClientRuntime.SigV4Config(signatureType: .requestQueryParams, useDoubleURIEncode: false, shouldNormalizeURIPath: false, expiration: expiration, unsignedBody: true, signingAlgorithm: .sigv4) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - """ + operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) +""" contents.shouldContainOnlyOnce(expectedContents) }