Skip to content

Commit cfcf8fa

Browse files
authored
fix: Eliminate compile warning in generated auth scheme resolvers (#976)
1 parent 2c8b006 commit cfcf8fa

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ import software.amazon.smithy.swift.codegen.utils.clientName
2727
import software.amazon.smithy.swift.codegen.utils.toLowerCamelCase
2828
import java.util.Locale
2929

30-
class AuthSchemeResolverGenerator(
31-
private val optionCustomization: ((String, SwiftWriter) -> SwiftWriter)? = null,
32-
) {
30+
class AuthSchemeResolverGenerator {
3331
fun render(ctx: ProtocolGenerator.GenerationContext) {
3432
val serviceIndex = ServiceIndex(ctx.model)
3533

@@ -257,10 +255,17 @@ class AuthSchemeResolverGenerator(
257255
) {
258256
writer.apply {
259257
val authOptionName = "${scheme.key.name}Option"
260-
write("var $authOptionName = \$N(schemeID: \$S)", SmithyHTTPAuthAPITypes.AuthOption, scheme.key)
261-
if (scheme.key == SigV4Trait.ID) renderSigV4AuthOptionCustomization(authOptionName, scheme, writer)
262-
optionCustomization?.invoke(authOptionName, writer)
263-
write("validAuthOptions.append($authOptionName)")
258+
val authOptionType = SmithyHTTPAuthAPITypes.AuthOption
259+
when (scheme.key) {
260+
SigV4Trait.ID -> {
261+
write("var \$L = \$N(schemeID: \$S)", authOptionName, authOptionType, scheme.key)
262+
renderSigV4AuthOptionCustomization(authOptionName, scheme, writer)
263+
}
264+
else -> {
265+
write("let \$L = \$N(schemeID: \$S)", authOptionName, authOptionType, scheme.key)
266+
}
267+
}
268+
write("validAuthOptions.append(\$L)", authOptionName)
264269
}
265270
}
266271

smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/requestandresponse/requestflow/AuthSchemeResolverGeneratorTests.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@ public struct DefaultExampleAuthSchemeResolver: ExampleAuthSchemeResolver {
4242
}
4343
switch serviceParams.operation {
4444
case "onlyHttpApiKeyAuth":
45-
var httpApiKeyAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpApiKeyAuth")
45+
let httpApiKeyAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpApiKeyAuth")
4646
validAuthOptions.append(httpApiKeyAuthOption)
4747
case "onlyHttpApiKeyAuthOptional":
48-
var httpApiKeyAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpApiKeyAuth")
48+
let httpApiKeyAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpApiKeyAuth")
4949
validAuthOptions.append(httpApiKeyAuthOption)
5050
validAuthOptions.append(SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#noAuth"))
5151
case "onlyHttpBearerAuth":
52-
var httpBearerAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpBearerAuth")
52+
let httpBearerAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpBearerAuth")
5353
validAuthOptions.append(httpBearerAuthOption)
5454
case "onlyHttpBearerAuthOptional":
55-
var httpBearerAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpBearerAuth")
55+
let httpBearerAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpBearerAuth")
5656
validAuthOptions.append(httpBearerAuthOption)
5757
validAuthOptions.append(SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#noAuth"))
5858
case "onlyHttpApiKeyAndBearerAuth":
59-
var httpApiKeyAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpApiKeyAuth")
59+
let httpApiKeyAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpApiKeyAuth")
6060
validAuthOptions.append(httpApiKeyAuthOption)
61-
var httpBearerAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpBearerAuth")
61+
let httpBearerAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpBearerAuth")
6262
validAuthOptions.append(httpBearerAuthOption)
6363
case "onlyHttpApiKeyAndBearerAuthReversed":
64-
var httpBearerAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpBearerAuth")
64+
let httpBearerAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpBearerAuth")
6565
validAuthOptions.append(httpBearerAuthOption)
66-
var httpApiKeyAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpApiKeyAuth")
66+
let httpApiKeyAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#httpApiKeyAuth")
6767
validAuthOptions.append(httpApiKeyAuthOption)
6868
case "onlySigv4Auth":
6969
var sigv4Option = SmithyHTTPAuthAPI.AuthOption(schemeID: "aws.auth#sigv4")
@@ -83,10 +83,10 @@ public struct DefaultExampleAuthSchemeResolver: ExampleAuthSchemeResolver {
8383
validAuthOptions.append(sigv4Option)
8484
validAuthOptions.append(SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#noAuth"))
8585
case "onlyCustomAuth":
86-
var customAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "com.test#customAuth")
86+
let customAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "com.test#customAuth")
8787
validAuthOptions.append(customAuthOption)
8888
case "onlyCustomAuthOptional":
89-
var customAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "com.test#customAuth")
89+
let customAuthOption = SmithyHTTPAuthAPI.AuthOption(schemeID: "com.test#customAuth")
9090
validAuthOptions.append(customAuthOption)
9191
validAuthOptions.append(SmithyHTTPAuthAPI.AuthOption(schemeID: "smithy.api#noAuth"))
9292
default:

0 commit comments

Comments
 (0)