diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt index 2801cec16..a90d2cd6b 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt @@ -54,6 +54,7 @@ class AuthSchemeResolverGenerator( "}", SmithyHTTPAuthAPITypes.AuthSchemeResolverParams, ) { + writer.write("public let authSchemePreference: \$N?", SwiftTypes.StringList) write("public let operation: \$N", SwiftTypes.String) if (usesRulesBasedAuthResolver(ctx)) { @@ -146,8 +147,6 @@ class AuthSchemeResolverGenerator( defaultResolverName, serviceSpecificAuthResolverProtocol, ) { - write("") - renderInit(writer) write("") renderResolveAuthSchemeMethod(serviceIndex, ctx, writer) write("") @@ -160,19 +159,6 @@ class AuthSchemeResolverGenerator( } } - private fun renderInit(writer: SwiftWriter) { - writer.apply { - write("public let authSchemePreference: [String]") - write("") - openBlock( - "public init(authSchemePreference: [String] = []) {", - "}", - ) { - write("self.authSchemePreference = authSchemePreference") - } - } - } - private fun renderResolveAuthSchemeMethod( serviceIndex: ServiceIndex, ctx: ProtocolGenerator.GenerationContext, @@ -200,7 +186,9 @@ class AuthSchemeResolverGenerator( // Render switch block renderSwitchBlock(serviceIndex, ctx, writer) // Call reprioritizeAuthOptions and return result - write("return self.reprioritizeAuthOptions(authSchemePreference: authSchemePreference, authOptions: validAuthOptions)") + write( + "return self.reprioritizeAuthOptions(authSchemePreference: serviceParams.authSchemePreference, authOptions: validAuthOptions)", + ) } } } @@ -317,12 +305,13 @@ class AuthSchemeResolverGenerator( SmithyTypes.ClientError, ) } + writer.write("let authSchemePreference = context.getAuthSchemePreference()") val paramType = getSdkId(ctx) + SmithyHTTPAuthAPITypes.AuthSchemeResolverParams.name if (hasSigV4) { write("let opRegion = context.getRegion()") - write("return $paramType(operation: opName, region: opRegion)") + write("return $paramType(authSchemePreference: authSchemePreference, operation: opName, region: opRegion)") } else { - write("return $paramType(operation: opName)") + write("return $paramType(authSchemePreference: authSchemePreference, operation: opName)") } } } diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/requestandresponse/requestflow/AuthSchemeResolverGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/requestandresponse/requestflow/AuthSchemeResolverGeneratorTests.kt index a590a3a15..8571e0aec 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/requestandresponse/requestflow/AuthSchemeResolverGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/requestandresponse/requestflow/AuthSchemeResolverGeneratorTests.kt @@ -21,6 +21,7 @@ class AuthSchemeResolverGeneratorTests { contents.shouldSyntacticSanityCheck() val expected = """ public struct ExampleAuthSchemeResolverParameters: SmithyHTTPAuthAPI.AuthSchemeResolverParameters { + public let authSchemePreference: [String]? public let operation: Swift.String // Region is used for SigV4 auth scheme public let region: Swift.String? @@ -34,12 +35,6 @@ public protocol ExampleAuthSchemeResolver: SmithyHTTPAuthAPI.AuthSchemeResolver public struct DefaultExampleAuthSchemeResolver: ExampleAuthSchemeResolver { - public let authSchemePreference: [String] - - public init(authSchemePreference: [String] = []) { - self.authSchemePreference = authSchemePreference - } - public func resolveAuthScheme(params: SmithyHTTPAuthAPI.AuthSchemeResolverParameters) throws -> [SmithyHTTPAuthAPI.AuthOption] { var validAuthOptions = [SmithyHTTPAuthAPI.AuthOption]() guard let serviceParams = params as? ExampleAuthSchemeResolverParameters else { @@ -103,15 +98,16 @@ public struct DefaultExampleAuthSchemeResolver: ExampleAuthSchemeResolver { sigv4Option.signingProperties.set(key: SmithyHTTPAuthAPI.SigningPropertyKeys.signingRegion, value: region) validAuthOptions.append(sigv4Option) } - return self.reprioritizeAuthOptions(authSchemePreference: authSchemePreference, authOptions: validAuthOptions) + return self.reprioritizeAuthOptions(authSchemePreference: serviceParams.authSchemePreference, authOptions: validAuthOptions) } public func constructParameters(context: Smithy.Context) throws -> SmithyHTTPAuthAPI.AuthSchemeResolverParameters { guard let opName = context.getOperation() else { throw Smithy.ClientError.dataNotFound("Operation name not configured in middleware context for auth scheme resolver params construction.") } + let authSchemePreference = context.getAuthSchemePreference() let opRegion = context.getRegion() - return ExampleAuthSchemeResolverParameters(operation: opName, region: opRegion) + return ExampleAuthSchemeResolverParameters(authSchemePreference: authSchemePreference, operation: opName, region: opRegion) } } """