Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stringArray type in endpoints params #3742

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
# message = "Fix typos in module documentation for generated crates"
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"
# author = "rcoh"

[[smithy-rs]]
message = "Support `stringArray` type in endpoints params"
references = ["smithy-rs#3742"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"}
author = "landonxjames"
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fun Model.sdkConfigSetter(
when (builtinType) {
ParameterType.STRING -> writable { rust("|s|s.to_string()") }
ParameterType.BOOLEAN -> null
// No builtins currently map to stringArray
else -> PANIC("needs to handle unimplemented endpoint parameter builtin type: $builtinType")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.endpoint

import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.shapes.BooleanShape
import software.amazon.smithy.model.shapes.ListShape
import software.amazon.smithy.model.shapes.ShapeType
import software.amazon.smithy.model.shapes.StringShape
import software.amazon.smithy.rulesengine.traits.ClientContextParamDefinition
Expand Down Expand Up @@ -51,6 +52,7 @@ class ClientContextConfigCustomization(ctx: ClientCodegenContext) : ConfigCustom
when (shapeType) {
ShapeType.STRING -> StringShape.builder().id("smithy.api#String").build()
ShapeType.BOOLEAN -> BooleanShape.builder().id("smithy.api#Boolean").build()
ShapeType.LIST -> ListShape.builder().id("smithy.api#List").build()
else -> TODO("unsupported type")
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fun Parameter.symbol(): Symbol {
when (this.type) {
ParameterType.STRING -> RustType.String
ParameterType.BOOLEAN -> RustType.Bool
ParameterType.STRING_ARRAY -> RustType.Vec(RustType.String)
else -> TODO("unexpected type: ${this.type}")
}
// Parameter return types are always optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators

import software.amazon.smithy.model.node.ArrayNode
import software.amazon.smithy.model.node.BooleanNode
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.node.StringNode
Expand Down Expand Up @@ -156,6 +157,12 @@ class EndpointParamsInterceptorGenerator(
when (node) {
is StringNode -> rust("Some(${node.value.dq()}.to_string())")
is BooleanNode -> rust("Some(${node.value})")
is ArrayNode -> {
// Cast the elements to a StringNode so this will fail if non-string values are provided
val elms = node.elements.map { "${(it as StringNode).value.dq()}.to_string()" }.joinToString(",")
rust("Some(vec![$elms])")
}

else -> PANIC("unsupported default value: $node")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ class EndpointsDecoratorTest {
}
}],
"parameters": {
"Bucket": { "required": false, "type": "String" },
"Region": { "required": false, "type": "String", "builtIn": "AWS::Region" },
"BuiltInWithDefault": { "required": true, "type": "String", "builtIn": "AWS::DefaultBuiltIn", "default": "some-default" },
"BoolBuiltInWithDefault": { "required": true, "type": "Boolean", "builtIn": "AWS::FooBar", "default": true },
"AStringParam": { "required": false, "type": "String" },
"ABoolParam": { "required": false, "type": "Boolean" }
"Bucket": { "required": false, "type": "string" },
"Region": { "required": false, "type": "string", "builtIn": "AWS::Region" },
"BuiltInWithDefault": { "required": true, "type": "string", "builtIn": "AWS::DefaultBuiltIn", "default": "some-default" },
"BoolBuiltInWithDefault": { "required": true, "type": "boolean", "builtIn": "AWS::FooBar", "default": true },
"AStringParam": { "required": false, "type": "string" },
"ABoolParam": { "required": false, "type": "boolean" },
"AStringArrayParam": { "required": false, "type": "stringArray" }
landonxjames marked this conversation as resolved.
Show resolved Hide resolved
}
})
@clientContextParams(
Expand Down Expand Up @@ -107,7 +108,10 @@ class EndpointsDecoratorTest {
operations: [TestOperation]
}

@staticContextParams(Region: { value: "us-east-2" })
@staticContextParams(
Region: { value: "us-east-2" },
AStringArrayParam: {value: ["a", "b", "c"]}
)
operation TestOperation {
input: TestOperationInput
}
Expand Down Expand Up @@ -184,6 +188,12 @@ class EndpointsDecoratorTest {
.a_bool_param(false)
.a_string_param("hello".to_string())
.region("us-east-2".to_string())
.a_string_array_param(
vec!["a", "b", "c"]
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
)
.build()
.unwrap()
);
Expand All @@ -198,6 +208,7 @@ class EndpointsDecoratorTest {

let interceptor = TestInterceptor::default();
let config = Config::builder()
.behavior_version_latest()
.http_client(NeverClient::new())
.interceptor(interceptor.clone())
.timeout_config(
Expand Down