Skip to content

Commit 2295d5b

Browse files
landonxjamesZelda Hessler
andauthored
Support stringArray type in endpoints params (#3742)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> ## Description <!--- Describe your changes in detail --> Updated our endpoint rule generation to support the new `stringArray` parameter type ## Testing <!--- Please describe in detail how you tested your changes --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> Updated the existing `EndpointsDecoratorTest` with tests for `stringArray` ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: Zelda Hessler <zhessler@amazon.com>
1 parent 20ad888 commit 2295d5b

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

CHANGELOG.next.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@
99
# message = "Fix typos in module documentation for generated crates"
1010
# references = ["smithy-rs#920"]
1111
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
12-
# author = "rcoh"
12+
# author = "rcoh"
13+
14+
[[smithy-rs]]
15+
message = "Support `stringArray` type in endpoints params"
16+
references = ["smithy-rs#3742"]
17+
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"}
18+
author = "landonxjames"

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ fun Model.sdkConfigSetter(
114114
when (builtinType) {
115115
ParameterType.STRING -> writable { rust("|s|s.to_string()") }
116116
ParameterType.BOOLEAN -> null
117+
// No builtins currently map to stringArray
117118
else -> PANIC("needs to handle unimplemented endpoint parameter builtin type: $builtinType")
118119
}
119120

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/ClientContextConfigCustomization.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.endpoint
77

88
import software.amazon.smithy.codegen.core.Symbol
99
import software.amazon.smithy.model.shapes.BooleanShape
10+
import software.amazon.smithy.model.shapes.ListShape
1011
import software.amazon.smithy.model.shapes.ShapeType
1112
import software.amazon.smithy.model.shapes.StringShape
1213
import software.amazon.smithy.rulesengine.traits.ClientContextParamDefinition
@@ -51,6 +52,7 @@ class ClientContextConfigCustomization(ctx: ClientCodegenContext) : ConfigCustom
5152
when (shapeType) {
5253
ShapeType.STRING -> StringShape.builder().id("smithy.api#String").build()
5354
ShapeType.BOOLEAN -> BooleanShape.builder().id("smithy.api#Boolean").build()
55+
ShapeType.LIST -> ListShape.builder().id("smithy.api#List").build()
5456
else -> TODO("unsupported type")
5557
},
5658
)

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ fun Parameter.symbol(): Symbol {
109109
when (this.type) {
110110
ParameterType.STRING -> RustType.String
111111
ParameterType.BOOLEAN -> RustType.Bool
112+
ParameterType.STRING_ARRAY -> RustType.Vec(RustType.String)
112113
else -> TODO("unexpected type: ${this.type}")
113114
}
114115
// Parameter return types are always optional

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

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

8+
import software.amazon.smithy.model.node.ArrayNode
89
import software.amazon.smithy.model.node.BooleanNode
910
import software.amazon.smithy.model.node.Node
1011
import software.amazon.smithy.model.node.StringNode
@@ -156,6 +157,12 @@ class EndpointParamsInterceptorGenerator(
156157
when (node) {
157158
is StringNode -> rust("Some(${node.value.dq()}.to_string())")
158159
is BooleanNode -> rust("Some(${node.value})")
160+
is ArrayNode -> {
161+
// Cast the elements to a StringNode so this will fail if non-string values are provided
162+
val elms = node.elements.map { "${(it as StringNode).value.dq()}.to_string()" }.joinToString(",")
163+
rust("Some(vec![$elms])")
164+
}
165+
159166
else -> PANIC("unsupported default value: $node")
160167
}
161168
}

codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecoratorTest.kt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ class EndpointsDecoratorTest {
5858
}
5959
}],
6060
"parameters": {
61-
"Bucket": { "required": false, "type": "String" },
62-
"Region": { "required": false, "type": "String", "builtIn": "AWS::Region" },
63-
"BuiltInWithDefault": { "required": true, "type": "String", "builtIn": "AWS::DefaultBuiltIn", "default": "some-default" },
64-
"BoolBuiltInWithDefault": { "required": true, "type": "Boolean", "builtIn": "AWS::FooBar", "default": true },
65-
"AStringParam": { "required": false, "type": "String" },
66-
"ABoolParam": { "required": false, "type": "Boolean" }
61+
"Bucket": { "required": false, "type": "string" },
62+
"Region": { "required": false, "type": "string", "builtIn": "AWS::Region" },
63+
"BuiltInWithDefault": { "required": true, "type": "string", "builtIn": "AWS::DefaultBuiltIn", "default": "some-default" },
64+
"BoolBuiltInWithDefault": { "required": true, "type": "boolean", "builtIn": "AWS::FooBar", "default": true },
65+
"AStringParam": { "required": false, "type": "string" },
66+
"ABoolParam": { "required": false, "type": "boolean" },
67+
"AStringArrayParam": { "required": false, "type": "stringArray" }
6768
}
6869
})
6970
@clientContextParams(
@@ -107,7 +108,10 @@ class EndpointsDecoratorTest {
107108
operations: [TestOperation]
108109
}
109110
110-
@staticContextParams(Region: { value: "us-east-2" })
111+
@staticContextParams(
112+
Region: { value: "us-east-2" },
113+
AStringArrayParam: {value: ["a", "b", "c"]}
114+
)
111115
operation TestOperation {
112116
input: TestOperationInput
113117
}
@@ -184,6 +188,12 @@ class EndpointsDecoratorTest {
184188
.a_bool_param(false)
185189
.a_string_param("hello".to_string())
186190
.region("us-east-2".to_string())
191+
.a_string_array_param(
192+
vec!["a", "b", "c"]
193+
.iter()
194+
.map(ToString::to_string)
195+
.collect::<Vec<_>>()
196+
)
187197
.build()
188198
.unwrap()
189199
);
@@ -198,6 +208,7 @@ class EndpointsDecoratorTest {
198208
199209
let interceptor = TestInterceptor::default();
200210
let config = Config::builder()
211+
.behavior_version_latest()
201212
.http_client(NeverClient::new())
202213
.interceptor(interceptor.clone())
203214
.timeout_config(

0 commit comments

Comments
 (0)