From 26d6535e07e4c1b3aa63e36512843da07acbd6be Mon Sep 17 00:00:00 2001 From: David Yaffe Date: Fri, 11 Jul 2025 15:31:53 -0400 Subject: [PATCH 1/3] fix authSchemePreference in config and remove from init in default resolver --- .../RulesBasedAuthSchemeResolverGenerator.kt | 4 +++- .../awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt | 1 + .../RulesBasedAuthSchemeResolverGeneratorTests.kt | 10 +++------- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/RulesBasedAuthSchemeResolverGenerator.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/RulesBasedAuthSchemeResolverGenerator.kt index b0780b93581..a4d2c608edd 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/RulesBasedAuthSchemeResolverGenerator.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/RulesBasedAuthSchemeResolverGenerator.kt @@ -222,6 +222,8 @@ class RulesBasedAuthSchemeResolverGenerator { ) } + writer.write("let authSchemePreference = context.getAuthSchemePreference()") + // Copy over endpoint param fields to auth param fields val ruleSetNode = ctx.service.getTrait()?.ruleSet val ruleSet = if (ruleSetNode != null) EndpointRuleSet.fromNode(ruleSetNode) else null @@ -234,7 +236,7 @@ class RulesBasedAuthSchemeResolverGenerator { } val argStringToAppend = if (paramList.isEmpty()) "" else ", " + paramList.joinToString() - write("return $returnTypeName(operation: opName$argStringToAppend)") + write("return $returnTypeName(authSchemePreference: authSchemePreference, operation: opName$argStringToAppend)") } } } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt index 483f48eb64e..343410b3fa6 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt @@ -57,6 +57,7 @@ extension ExplicitBlobInput { val context = setupTests("http-binding-protocol-generator-test.smithy", "com.test#Example") val contents = getClientFileContents("Sources/Example", "ExampleClient.swift", context.manifest) contents.shouldSyntacticSanityCheck() + print(contents) val expectedContents = """ public class ExampleClient: ClientRuntime.Client { public static let clientName = "ExampleClient" diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/RulesBasedAuthSchemeResolverGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/RulesBasedAuthSchemeResolverGeneratorTests.kt index 148a53fe2af..a69ebaa719d 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/RulesBasedAuthSchemeResolverGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/RulesBasedAuthSchemeResolverGeneratorTests.kt @@ -21,6 +21,7 @@ class RulesBasedAuthSchemeResolverGeneratorTests { contents.shouldSyntacticSanityCheck() val expectedContents = """ public struct S3AuthSchemeResolverParameters: SmithyHTTPAuthAPI.AuthSchemeResolverParameters { + public let authSchemePreference: [String]? public let operation: Swift.String } @@ -32,12 +33,6 @@ public protocol S3AuthSchemeResolver: SmithyHTTPAuthAPI.AuthSchemeResolver { private struct InternalModeledS3AuthSchemeResolver: S3AuthSchemeResolver { - 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? S3AuthSchemeResolverParameters else { @@ -200,7 +195,8 @@ public struct DefaultS3AuthSchemeResolver: S3AuthSchemeResolver { guard let endpointParam = context.get(key: Smithy.AttributeKey(name: "EndpointParams")) else { throw Smithy.ClientError.dataNotFound("Endpoint param not configured in middleware context for rules-based auth scheme resolver params construction.") } - return S3AuthSchemeResolverParameters(operation: opName) + let authSchemePreference = context.getAuthSchemePreference() + return S3AuthSchemeResolverParameters(authSchemePreference: authSchemePreference, operation: opName) } } """ From fa6fbc9f260330e0f4ad204a55f847374b111930 Mon Sep 17 00:00:00 2001 From: David Yaffe Date: Fri, 11 Jul 2025 15:59:16 -0400 Subject: [PATCH 2/3] fix more tests --- .../RulesBasedAuthSchemeResolverGeneratorTests.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/RulesBasedAuthSchemeResolverGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/RulesBasedAuthSchemeResolverGeneratorTests.kt index a69ebaa719d..69c00e2d103 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/RulesBasedAuthSchemeResolverGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/RulesBasedAuthSchemeResolverGeneratorTests.kt @@ -135,7 +135,7 @@ private struct InternalModeledS3AuthSchemeResolver: S3AuthSchemeResolver { sigv4Option.identityProperties.set(key: AWSSDKIdentity.InternalClientKeys.internalSSOOIDCClientKey, value: InternalAWSSSOOIDC.IdentityProvidingSSOOIDCClient()) 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 { From 42b2fe8ebc649dd5b57178e93ddb4dde4cc26851 Mon Sep 17 00:00:00 2001 From: David Yaffe Date: Fri, 11 Jul 2025 16:22:42 -0400 Subject: [PATCH 3/3] remove print --- .../codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt index 343410b3fa6..483f48eb64e 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt @@ -57,7 +57,6 @@ extension ExplicitBlobInput { val context = setupTests("http-binding-protocol-generator-test.smithy", "com.test#Example") val contents = getClientFileContents("Sources/Example", "ExampleClient.swift", context.manifest) contents.shouldSyntacticSanityCheck() - print(contents) val expectedContents = """ public class ExampleClient: ClientRuntime.Client { public static let clientName = "ExampleClient"