From dcc2172512d86ac43f9a0a72e972178a6e0f008a Mon Sep 17 00:00:00 2001 From: Sichan Yoo Date: Thu, 1 Aug 2024 12:42:05 -0700 Subject: [PATCH] Use string provided in builtIn property for code generating endpoint params construction. --- .../OperationEndpointResolverMiddleware.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 02032705792..b003e3c963f 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 @@ -131,11 +131,11 @@ class OperationEndpointResolverMiddleware( param.isRequired -> { when { param.default.isPresent -> { - "config.${param.name.toString().toLowerCamelCase()} ?? ${param.defaultValueLiteral}" + "config.${getBuiltInName(param)} ?? ${param.defaultValueLiteral}" } else -> { // if the parameter is required, we must unwrap the optional value - writer.openBlock("guard let ${param.name.toString().toLowerCamelCase()} = config.${param.name.toString().toLowerCamelCase()} else {", "}") { + writer.openBlock("guard let ${getBuiltInName(param)} = config.${getBuiltInName(param)} else {", "}") { writer.write("throw \$N.unknownError(\"Missing required parameter: \$L\")", SmithyTypes.ClientError, param.name.toString()) } param.name.toString().toLowerCamelCase() @@ -143,10 +143,10 @@ class OperationEndpointResolverMiddleware( } } param.default.isPresent -> { - "config.${param.name.toString().toLowerCamelCase()} ?? ${param.defaultValueLiteral}" + "config.${getBuiltInName(param)} ?? ${param.defaultValueLiteral}" } else -> { - "config.${param.name.toString().toLowerCamelCase()}" + "config.${getBuiltInName(param)}" } } } @@ -156,6 +156,10 @@ class OperationEndpointResolverMiddleware( } } } + + private fun getBuiltInName(param: Parameter): String { + return param.builtIn.get().split("::").last().toLowerCamelCase() + } } private val Parameter.defaultValueLiteral: String