From afdf6096a735f1fd33cbca96f39832233dd18514 Mon Sep 17 00:00:00 2001 From: Chan <55515281+sichanyoo@users.noreply.github.com> Date: Mon, 5 Aug 2024 10:42:19 -0700 Subject: [PATCH] Use string provided in builtIn property for code generating endpoint params construction. (#1658) Co-authored-by: Sichan Yoo --- .../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