Skip to content

Commit 3b6fce6

Browse files
authored
fix: disambiguate sdk types (#292)
1 parent 0507cd6 commit 3b6fce6

29 files changed

+175
-128
lines changed

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSClientRuntimeTypes.kt

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,45 @@ import software.amazon.smithy.codegen.core.Symbol
44
import software.amazon.smithy.swift.codegen.model.buildSymbol
55

66
object AWSClientRuntimeTypes {
7+
object EC2Query {
8+
val Ec2NarrowedResponse = runtimeSymbol("Ec2NarrowedResponse")
9+
}
10+
object AWSJSON {
11+
val XAmzTargetMiddleware = runtimeSymbol("XAmzTargetMiddleware")
12+
}
13+
object RestJSON {
14+
val RestJSONError = runtimeSymbol("RestJSONError")
15+
}
16+
17+
object RestXML {
18+
val RestXMLError = runtimeSymbol("RestXMLError")
19+
}
20+
21+
object Signing {
22+
val SigV4Config = runtimeSymbol("SigV4Config")
23+
val SigV4Middleware = runtimeSymbol("SigV4Middleware")
24+
}
25+
726
object Core {
8-
val EndpointResolver = runtimeSymbol("EndpointResolver", AWSSwiftDependency.AWS_CLIENT_RUNTIME)
9-
val CredentialsProvider = runtimeSymbol("AWSCredentialsProvider", AWSSwiftDependency.AWS_CLIENT_RUNTIME)
27+
val AWSUserAgentMetadata = runtimeSymbol("AWSUserAgentMetadata")
28+
val APIMetadata = runtimeSymbol("APIMetadata")
29+
val UserAgentMiddleware = runtimeSymbol("UserAgentMiddleware")
30+
val RetrierMiddleware = runtimeSymbol("RetrierMiddleware")
31+
val EndpointResolverMiddleware = runtimeSymbol("EndpointResolverMiddleware")
32+
val EndpointResolver = runtimeSymbol("EndpointResolver")
33+
val CredentialsProvider = runtimeSymbol("AWSCredentialsProvider")
34+
val AWSClientConfiguration = runtimeSymbol("AWSClientConfiguration")
35+
val AWSEndpoint = runtimeSymbol("AWSEndpoint")
36+
val Partition = runtimeSymbol("Partition")
37+
val ServiceEndpointMetadata = runtimeSymbol("ServiceEndpointMetadata")
38+
val CredentialScope = runtimeSymbol("CredentialScope")
39+
val UnknownAWSHttpServiceError = runtimeSymbol("UnknownAWSHttpServiceError")
40+
val AWSHttpServiceError = runtimeSymbol("AWSHttpServiceError")
1041
}
1142
}
1243

13-
private fun runtimeSymbol(name: String, dependency: AWSSwiftDependency): Symbol = buildSymbol {
44+
private fun runtimeSymbol(name: String): Symbol = buildSymbol {
1445
this.name = name
15-
dependency(dependency)
46+
this.namespace = AWSSwiftDependency.AWS_CLIENT_RUNTIME.target
47+
dependency(AWSSwiftDependency.AWS_CLIENT_RUNTIME)
1648
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSHttpBindingProtocolGenerator.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,9 @@ import software.amazon.smithy.swift.codegen.model.ShapeMetadata
2222

2323
abstract class AWSHttpBindingProtocolGenerator : HttpBindingProtocolGenerator() {
2424

25-
override val serviceErrorProtocolSymbol: Symbol = Symbol.builder()
26-
.name("AWSHttpServiceError")
27-
.namespace(AWSSwiftDependency.AWS_CLIENT_RUNTIME.target, "")
28-
.addDependency(AWSSwiftDependency.AWS_CLIENT_RUNTIME)
29-
.build()
25+
override val serviceErrorProtocolSymbol: Symbol = AWSClientRuntimeTypes.Core.AWSHttpServiceError
3026

31-
override val unknownServiceErrorSymbol: Symbol = Symbol.builder()
32-
.name("UnknownAWSHttpServiceError")
33-
.namespace(AWSSwiftDependency.AWS_CLIENT_RUNTIME.target, "")
34-
.addDependency(AWSSwiftDependency.AWS_CLIENT_RUNTIME)
35-
.build()
27+
override val unknownServiceErrorSymbol: Symbol = AWSClientRuntimeTypes.Core.UnknownAWSHttpServiceError
3628

3729
val serdeContextJSON = HttpProtocolUnitTestGenerator.SerdeContext("JSONEncoder()", "JSONDecoder()", ".secondsSince1970")
3830
val serdeContextXML = HttpProtocolUnitTestGenerator.SerdeContext("XMLEncoder()", "XMLDecoder()")

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSHttpProtocolServiceClient.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package software.amazon.smithy.aws.swift.codegen
22

33
import software.amazon.smithy.codegen.core.Symbol
4+
import software.amazon.smithy.swift.codegen.SwiftTypes
45
import software.amazon.smithy.swift.codegen.SwiftWriter
56
import software.amazon.smithy.swift.codegen.integration.ClientProperty
67
import software.amazon.smithy.swift.codegen.integration.HttpProtocolServiceClient
@@ -14,7 +15,7 @@ class AWSHttpProtocolServiceClient(
1415
private val serviceConfig: ServiceConfig
1516
) : HttpProtocolServiceClient(ctx, writer, properties, serviceConfig) {
1617
override fun renderConvenienceInit(serviceSymbol: Symbol) {
17-
writer.openBlock("public convenience init(region: String? = nil) throws {", "}") {
18+
writer.openBlock("public convenience init(region: \$D) throws {", "}", SwiftTypes.String) {
1819
writer.write("let unwrappedRegion = region ?? \"us-east-1\"") // TODO: replace with call to region resolver
1920
writer.write("let config = try ${serviceConfig.typeName}(region: unwrappedRegion)")
2021
writer.write("self.init(config: config)")
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package software.amazon.smithy.aws.swift.codegen
22

3+
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
34
import software.amazon.smithy.swift.codegen.integration.HttpRequestEncoder
45

56
class AWSHttpRequestFormURLEncoder(
67
requestEncoderOptions: MutableMap<String, String> = mutableMapOf()
7-
) : HttpRequestEncoder("FormURLEncoder", requestEncoderOptions)
8+
) : HttpRequestEncoder(ClientRuntimeTypes.Serde.FormURLEncoder, requestEncoderOptions)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package software.amazon.smithy.aws.swift.codegen
22

3+
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
34
import software.amazon.smithy.swift.codegen.integration.HttpRequestEncoder
45

56
class AWSHttpRequestJsonEncoder(
67
requestEncoderOptions: MutableMap<String, String> = mutableMapOf()
7-
) : HttpRequestEncoder("JSONEncoder", requestEncoderOptions)
8+
) : HttpRequestEncoder(ClientRuntimeTypes.Serde.JSONEncoder, requestEncoderOptions)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package software.amazon.smithy.aws.swift.codegen
22

3+
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
34
import software.amazon.smithy.swift.codegen.integration.HttpRequestEncoder
45

56
class AWSHttpRequestXMLEncoder(
67
requestEncoderOptions: MutableMap<String, String> = mutableMapOf()
7-
) : HttpRequestEncoder("XMLEncoder", requestEncoderOptions)
8+
) : HttpRequestEncoder(ClientRuntimeTypes.Serde.XMLEncoder, requestEncoderOptions)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package software.amazon.smithy.aws.swift.codegen
22

3+
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
34
import software.amazon.smithy.swift.codegen.integration.HttpResponseDecoder
45

56
class AWSHttpResponseJsonDecoder(
67
responseDecoderOptions: MutableMap<String, String> = mutableMapOf()
7-
) : HttpResponseDecoder("JSONDecoder", responseDecoderOptions)
8+
) : HttpResponseDecoder(ClientRuntimeTypes.Serde.JSONDecoder, responseDecoderOptions)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package software.amazon.smithy.aws.swift.codegen
22

3+
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
34
import software.amazon.smithy.swift.codegen.integration.HttpResponseDecoder
45

56
class AWSHttpResponseXMLDecoder(
67
responseDecoderOptions: MutableMap<String, String> = mutableMapOf()
7-
) : HttpResponseDecoder("XMLDecoder", responseDecoderOptions)
8+
) : HttpResponseDecoder(ClientRuntimeTypes.Serde.XMLDecoder, responseDecoderOptions)

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSServiceConfig.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
package software.amazon.smithy.aws.swift.codegen
22

33
import software.amazon.smithy.codegen.core.Symbol
4+
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
5+
import software.amazon.smithy.swift.codegen.SwiftTypes
46
import software.amazon.smithy.swift.codegen.SwiftWriter
57
import software.amazon.smithy.swift.codegen.integration.ConfigField
68
import software.amazon.smithy.swift.codegen.integration.ServiceConfig
7-
import software.amazon.smithy.swift.codegen.model.buildSymbol
89

910
const val REGION_CONFIG_NAME = "region"
1011
const val CREDENTIALS_PROVIDER_CONFIG_NAME = "credentialsProvider"
1112
const val SIGNING_REGION_CONFIG_NAME = "signingRegion"
1213
const val ENDPOINT_RESOLVER = "endpointResolver"
1314

1415
class AWSServiceConfig(writer: SwiftWriter, serviceName: String) : ServiceConfig(writer, serviceName) {
15-
override val typesToConformConfigTo: List<String>
16-
get() = listOf("AWSClientConfiguration")
16+
override val typesToConformConfigTo: List<Symbol>
17+
get() = listOf(AWSClientRuntimeTypes.Core.AWSClientConfiguration)
1718

1819
override fun renderInitializers(serviceSymbol: Symbol) {
1920
val awsConfigFields = otherRuntimeConfigProperties()
2021
writer.openBlock("public init(", ") throws {") {
2122
awsConfigFields.forEach {
22-
writer.write("${it.memberName}: \$D, ", it.type)
23+
val formatter = if (it.memberName == "region") "\$N" else "\$D"
24+
writer.write("${it.memberName}: $formatter, ", it.type)
2325
}
24-
writer.write("runtimeConfig: SDKRuntimeConfiguration")
26+
writer.write("runtimeConfig: \$N", ClientRuntimeTypes.Core.SDKRuntimeConfiguration)
2527
}
2628
writer.indent()
2729
writer.write("self.region = region")
@@ -30,7 +32,7 @@ class AWSServiceConfig(writer: SwiftWriter, serviceName: String) : ServiceConfig
3032
writer.openBlock("if let credProvider = credentialsProvider {", "} else {") {
3133
writer.write("self.credentialsProvider = credProvider")
3234
}
33-
writer.indent().write("self.credentialsProvider = try AWSCredentialsProvider.fromChain()")
35+
writer.indent().write("self.credentialsProvider = try \$N.fromChain()", AWSClientRuntimeTypes.Core.CredentialsProvider)
3436
writer.dedent().write("}")
3537
val runtimeTimeConfigFields = sdkRuntimeConfigProperties()
3638
runtimeTimeConfigFields.forEach {
@@ -43,7 +45,8 @@ class AWSServiceConfig(writer: SwiftWriter, serviceName: String) : ServiceConfig
4345

4446
awsConfigFields.forEachIndexed { index, configField ->
4547
val terminator = if (index != awsConfigFields.lastIndex) ", " else ""
46-
writer.write("${configField.memberName}: \$D$terminator", configField.type)
48+
val formatter = if (configField.memberName == "region") "\$N" else "\$D"
49+
writer.write("${configField.memberName}: $formatter$terminator", configField.type)
4750
}
4851
}
4952

@@ -52,7 +55,7 @@ class AWSServiceConfig(writer: SwiftWriter, serviceName: String) : ServiceConfig
5255
configParamValues += "${it.memberName}: ${it.memberName}, "
5356
}
5457
writer.indent()
55-
writer.write("let defaultRuntimeConfig = try DefaultSDKRuntimeConfiguration(\"${serviceName}\")")
58+
writer.write("let defaultRuntimeConfig = try \$N(\"${serviceName}\")", ClientRuntimeTypes.Core.DefaultSDKRuntimeConfiguration)
5659
writer.write("try self.init(${configParamValues}runtimeConfig: defaultRuntimeConfig)")
5760
writer.dedent().write("}")
5861
}
@@ -61,17 +64,14 @@ class AWSServiceConfig(writer: SwiftWriter, serviceName: String) : ServiceConfig
6164
return listOf(
6265
ConfigField(
6366
REGION_CONFIG_NAME,
64-
buildSymbol {
65-
this.name = "String"
66-
this.nullable = false
67-
},
67+
SwiftTypes.String,
6868
"The region to send requests to. (Required)"
6969
),
7070
ConfigField(
7171
CREDENTIALS_PROVIDER_CONFIG_NAME, AWSClientRuntimeTypes.Core.CredentialsProvider,
7272
"The credentials provider to use to authenticate requests."
7373
),
74-
ConfigField(SIGNING_REGION_CONFIG_NAME, buildSymbol { this.name = "String" }, "The region to sign requests in. (Required)"),
74+
ConfigField(SIGNING_REGION_CONFIG_NAME, SwiftTypes.String, "The region to sign requests in. (Required)"),
7575
ConfigField(
7676
ENDPOINT_RESOLVER, AWSClientRuntimeTypes.Core.EndpointResolver,
7777
"The endpoint resolver used to resolve endpoints."

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverGenerator.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class EndpointResolverGenerator(private val endpointData: ObjectNode) {
2323
private fun renderResolver(writer: SwiftWriter) {
2424
writer.addImport(AWSSwiftDependency.AWS_CLIENT_RUNTIME.target)
2525

26-
writer.openBlock("struct DefaultEndpointResolver : EndpointResolver {", "}") {
27-
writer.openBlock("func resolve(serviceId: String, region: String) throws -> AWSEndpoint {", "}") {
28-
writer.write("return try AWSEndpoint.resolveEndpoint(partitions: servicePartitions, region: region)")
26+
writer.openBlock("struct DefaultEndpointResolver : \$N {", "}", AWSClientRuntimeTypes.Core.EndpointResolver) {
27+
writer.openBlock("func resolve(serviceId: String, region: String) throws -> \$N {", "}", AWSClientRuntimeTypes.Core.AWSEndpoint) {
28+
writer.write("return try \$N.resolveEndpoint(partitions: servicePartitions, region: region)", AWSClientRuntimeTypes.Core.AWSEndpoint)
2929
}
3030
}
3131
}
@@ -45,12 +45,12 @@ class EndpointResolverGenerator(private val endpointData: ObjectNode) {
4545
}
4646

4747
private fun renderPartition(writer: SwiftWriter, partitionNode: PartitionNode) {
48-
writer.openBlock("AWSClientRuntime.Partition(", "),") {
48+
writer.openBlock("\$N(", "),", AWSClientRuntimeTypes.Core.Partition) {
4949
writer.write("id: \$S,", partitionNode.id)
5050
.write("regionRegex: \$S,", partitionNode.config.expectStringMember("regionRegex").value)
5151
.write("partitionEndpoint: \$S,", partitionNode.partitionEndpoint ?: "")
5252
.write("isRegionalized: \$L,", partitionNode.partitionEndpoint == null)
53-
.openBlock("defaults: ServiceEndpointMetadata(", "),") {
53+
.openBlock("defaults: \$N(", "),", AWSClientRuntimeTypes.Core.ServiceEndpointMetadata) {
5454
renderServiceEndpointMetadata(writer, partitionNode.defaults)
5555
}
5656
.openBlock("endpoints: [", "]") {
@@ -66,9 +66,9 @@ class EndpointResolverGenerator(private val endpointData: ObjectNode) {
6666
partitionNode.endpoints.members.forEach {
6767
val definitionNode = it.value.expectObjectNode()
6868
if (definitionNode.members.isEmpty()) {
69-
writer.write("\$S: ServiceEndpointMetadata(),", it.key.value)
69+
writer.write("\$S: \$N(),", it.key.value, AWSClientRuntimeTypes.Core.ServiceEndpointMetadata)
7070
} else {
71-
writer.openBlock("\$S: ServiceEndpointMetadata(", "),", it.key.value) {
71+
writer.openBlock("\$S: \$N(", "),", it.key.value, AWSClientRuntimeTypes.Core.ServiceEndpointMetadata) {
7272
renderServiceEndpointMetadata(writer, it.value.expectObjectNode())
7373
}
7474
}
@@ -96,7 +96,7 @@ class EndpointResolverGenerator(private val endpointData: ObjectNode) {
9696
}
9797

9898
credentialScope.ifPresent {
99-
writer.writeInline("credentialScope: CredentialScope(")
99+
writer.writeInline("credentialScope: \$N(", AWSClientRuntimeTypes.Core.CredentialScope)
100100
val region = it.getStringMember("region")
101101
val service = it.getStringMember("service")
102102
region.ifPresent {

0 commit comments

Comments
 (0)