Skip to content

Commit

Permalink
Use string provided in builtIn property for code generating endpoint …
Browse files Browse the repository at this point in the history
…params construction. (#1658)

Co-authored-by: Sichan Yoo <chanyoo@amazon.com>
  • Loading branch information
sichanyoo and Sichan Yoo authored Aug 5, 2024
1 parent c3d470f commit afdf609
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ 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()
}
}
}
param.default.isPresent -> {
"config.${param.name.toString().toLowerCamelCase()} ?? ${param.defaultValueLiteral}"
"config.${getBuiltInName(param)} ?? ${param.defaultValueLiteral}"
}
else -> {
"config.${param.name.toString().toLowerCamelCase()}"
"config.${getBuiltInName(param)}"
}
}
}
Expand All @@ -156,6 +156,10 @@ class OperationEndpointResolverMiddleware(
}
}
}

private fun getBuiltInName(param: Parameter): String {
return param.builtIn.get().split("::").last().toLowerCamelCase()
}
}

private val Parameter.defaultValueLiteral: String
Expand Down

0 comments on commit afdf609

Please sign in to comment.