diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index fc4c4c2578..888d69fe48 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -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" \ No newline at end of file +# 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" diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt index efcb19f15a..b2407859b5 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt @@ -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") } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/ClientContextConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/ClientContextConfigCustomization.kt index adf7bfddb5..ddf58c8887 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/ClientContextConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/ClientContextConfigCustomization.kt @@ -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 @@ -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") }, ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt index 43b79f16fc..d22642edc7 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/Util.kt @@ -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 diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt index 458128842e..fe52308f90 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt @@ -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 @@ -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") } } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecoratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecoratorTest.kt index 0e5ab3ff78..854fa5143a 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecoratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointsDecoratorTest.kt @@ -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" } } }) @clientContextParams( @@ -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 } @@ -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::>() + ) .build() .unwrap() ); @@ -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(