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 7c59af0b3e5..a8a970b5a62 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 @@ -6,6 +6,7 @@ package software.amazon.smithy.aws.swift.codegen.middleware import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rulesengine.language.EndpointRuleSet @@ -115,15 +116,7 @@ class OperationEndpointResolverMiddleware( ): String? { return when { staticContextParam != null -> { - return when (param.type) { - ParameterType.STRING -> { - "\"${staticContextParam.value}\"" - } - - ParameterType.BOOLEAN -> { - staticContextParam.value.toString() - } - } + swiftParam(param.type, staticContextParam.value) } contextParam != null -> { return "input.${contextParam.memberName.toLowerCamelCase()}" @@ -171,9 +164,12 @@ class OperationEndpointResolverMiddleware( } private val Parameter.defaultValueLiteral: String - get() { - return when (type) { - ParameterType.BOOLEAN -> default.get().toString() - ParameterType.STRING -> "\"${default.get()}\"" - } + get() = swiftParam(type, default.get().toNode()) + +private fun swiftParam(parameterType: ParameterType, node: Node): String { + return when (parameterType) { + ParameterType.STRING -> "\"${node}\"" + ParameterType.BOOLEAN -> node.toString() + ParameterType.STRING_ARRAY -> "[${node.expectArrayNode().map { "\"$it\"" }.joinToString(", ")}]" } +} diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/model/AWSClientContextParamsTransformer.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/model/AWSClientContextParamsTransformer.kt index 0458c7e17ec..dae6e272e82 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/model/AWSClientContextParamsTransformer.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/model/AWSClientContextParamsTransformer.kt @@ -61,6 +61,6 @@ fun ParameterType.toShapeType(): ShapeType? { return when (this) { ParameterType.STRING -> ShapeType.STRING ParameterType.BOOLEAN -> ShapeType.BOOLEAN - else -> null + ParameterType.STRING_ARRAY -> ShapeType.LIST } } diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/model/AWSDeprecatedShapeRemover.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/model/AWSDeprecatedShapeRemover.kt index 0776ad72f72..382e7d605d3 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/model/AWSDeprecatedShapeRemover.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/model/AWSDeprecatedShapeRemover.kt @@ -28,7 +28,7 @@ class AWSDeprecatedShapeRemover : SwiftIntegration { Predicate { val since = it.getTrait()?.since?.orElse(null) ?: return@Predicate false val deprecatedDate = since.toLocalDate() ?: return@Predicate false.also { - println("Failed to parse `since` field $since as a date, skipping removal of deprecated shape $it") + println("Could not parse `since` field \"$since\" as a date, skipping removal of deprecated shape $it") } return@Predicate deprecatedDate < REMOVE_BEFORE_DATE.toLocalDate() } diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/ec2query/EC2QueryProtocolGenerator.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/ec2query/EC2QueryProtocolGenerator.kt index 9f3e44751ab..21eb24eba70 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/ec2query/EC2QueryProtocolGenerator.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/protocols/ec2query/EC2QueryProtocolGenerator.kt @@ -27,6 +27,7 @@ class EC2QueryProtocolGenerator : AWSHTTPBindingProtocolGenerator(EC2QueryCustom override val testsToIgnore = setOf( "SDKAppliedContentEncoding_ec2Query", "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_ec2Query", + "Ec2EmptyQueryLists", ) override val tagsToIgnore = setOf("defaults") diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointParamsGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointParamsGeneratorTests.kt index 518f8b6c760..689c47edb11 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointParamsGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointParamsGeneratorTests.kt @@ -80,38 +80,41 @@ class EndpointParamsGeneratorTests { endpointParamsGenerator.render(writer) val contents = writer.toString() val expected = """ - public struct EndpointParams { - public let boolBar: Swift.Bool? - public let boolBaz: Swift.String? - public let boolFoo: Swift.Bool - public let endpoint: Swift.String? - public let region: Swift.String - public let stringBar: Swift.String? - public let stringBaz: Swift.String? - public let stringFoo: Swift.String? - - public init( - boolBar: Swift.Bool? = nil, - boolBaz: Swift.String? = nil, - boolFoo: Swift.Bool, - endpoint: Swift.String? = nil, - region: Swift.String, - stringBar: Swift.String? = nil, - stringBaz: Swift.String? = nil, - stringFoo: Swift.String? = nil - ) - { - self.boolBar = boolBar - self.boolBaz = boolBaz - self.boolFoo = boolFoo - self.endpoint = endpoint - self.region = region - self.stringBar = stringBar - self.stringBaz = stringBaz - self.stringFoo = stringFoo - } - } - """.trimIndent() +public struct EndpointParams { + public let boolBar: Swift.Bool? + public let boolBaz: Swift.String? + public let boolFoo: Swift.Bool + public let endpoint: Swift.String? + public let region: Swift.String + public let stringArrayBar: Swift.Array? + public let stringBar: Swift.String? + public let stringBaz: Swift.String? + public let stringFoo: Swift.String? + + public init( + boolBar: Swift.Bool? = nil, + boolBaz: Swift.String? = nil, + boolFoo: Swift.Bool, + endpoint: Swift.String? = nil, + region: Swift.String, + stringArrayBar: Swift.Array? = nil, + stringBar: Swift.String? = nil, + stringBaz: Swift.String? = nil, + stringFoo: Swift.String? = nil + ) + { + self.boolBar = boolBar + self.boolBaz = boolBaz + self.boolFoo = boolFoo + self.endpoint = endpoint + self.region = region + self.stringArrayBar = stringArrayBar + self.stringBar = stringBar + self.stringBaz = stringBaz + self.stringFoo = stringFoo + } +} +""" contents.shouldContainOnlyOnce(expected) } } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/OperationEndpointResolverMiddlewareTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/OperationEndpointResolverMiddlewareTests.kt index 09321a31f9a..6f41329a6c1 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/OperationEndpointResolverMiddlewareTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/OperationEndpointResolverMiddlewareTests.kt @@ -25,7 +25,7 @@ class OperationEndpointResolverMiddlewareTests { guard let region = config.region else { throw SdkError.client(ClientError.unknownError(("Missing required parameter: region"))) } -let endpointParams = EndpointParams(boolBar: true, boolBaz: input.fuzz, boolFoo: config.boolFoo, endpoint: config.endpoint, region: region, stringBar: "some value", stringBaz: input.buzz, stringFoo: config.stringFoo) +let endpointParams = EndpointParams(boolBar: true, boolBaz: input.fuzz, boolFoo: config.boolFoo, endpoint: config.endpoint, region: region, stringArrayBar: ["five", "six", "seven"], stringBar: "some value", stringBaz: input.buzz, stringFoo: config.stringFoo) operationStack.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.endpointResolver, endpointParams: endpointParams)) """ contents.shouldContainOnlyOnce(expected) diff --git a/codegen/smithy-aws-swift-codegen/src/test/resources/software.amazon.smithy.aws.swift.codegen/endpoints.smithy b/codegen/smithy-aws-swift-codegen/src/test/resources/software.amazon.smithy.aws.swift.codegen/endpoints.smithy index 75aa5a19f0a..d86e490667e 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/resources/software.amazon.smithy.aws.swift.codegen/endpoints.smithy +++ b/codegen/smithy-aws-swift-codegen/src/test/resources/software.amazon.smithy.aws.swift.codegen/endpoints.smithy @@ -10,7 +10,7 @@ use smithy.rules#endpointRuleSet @clientContextParams( stringFoo: {type: "string", documentation: "a client string parameter"}, - boolFoo: {type: "boolean", documentation: "a client boolean parameter"} + boolFoo: {type: "boolean", documentation: "a client boolean parameter"}, ) @service( sdkId: "Json Protocol", @@ -33,6 +33,7 @@ apply ExampleService @endpointRuleSet({ boolFoo: {type: "boolean", required: true}, boolBar: {type: "boolean"}, boolBaz: {type: "string"}, + stringArrayBar: {type: "stringArray"}, region: {type: "string", builtIn: "AWS::Region", required: true}, }, rules: [] @@ -42,6 +43,7 @@ apply ExampleService @endpointRuleSet({ @staticContextParams( stringBar: {value: "some value"}, boolBar: {value: true} + stringArrayBar: {value: ["five", "six", "seven"]} ) @http(method: "POST", uri: "/endpointtest/getthing") operation GetThing { @@ -53,8 +55,8 @@ structure GetThingInput { fizz: String, @contextParam(name: "stringBaz") - buzz: String, + buzz: String @contextParam(name: "boolBaz") - fuzz: String, + fuzz: String } diff --git a/gradle.properties b/gradle.properties index d2520f8982c..12cf3740445 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ kotlin.code.style=official org.gradle.jvmargs=-Xmx4096M # codegen -smithyVersion=1.47.0 +smithyVersion=1.49.0 smithyGradleVersion=0.6.0 smithySwiftVersion = 0.1.0