Skip to content

Commit 5fb51db

Browse files
authored
feat(codegen): add order parameter to ClientConfigProperty to be used for ordering configuration dependencies (#721)
1 parent 8c2a115 commit 5fb51db

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "490f40f2-97e1-47f9-b53c-d0740e394814",
3+
"type": "feature",
4+
"description": "Add order parameter to ClientConfigProperty to be used for ordering configuration dependencies",
5+
"issues": ["awslabs/aws-sdk-kotlin/#711"]
6+
}

smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/ClientConfigGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ClientConfigGenerator(
6868

6969
addPropertyImports()
7070

71-
props.sortBy { it.propertyName }
71+
props.sortWith(compareBy({ it.order }, { it.propertyName }))
7272
val baseClasses = props
7373
.mapNotNull { it.baseClass?.name }
7474
.toSet()

smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/ClientConfigProperty.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class ClientConfigProperty private constructor(builder: Builder) {
6969
*/
7070
val additionalImports: List<Symbol> = builder.additionalImports
7171

72+
/**
73+
* The priority order of rendering the property. Used to manage dependencies between configuration properties.
74+
*/
75+
val order: Int = builder.order
76+
7277
/**
7378
* Flag indicating if this property stems from some base class and needs an override modifier when rendered
7479
*/
@@ -144,6 +149,8 @@ class ClientConfigProperty private constructor(builder: Builder) {
144149

145150
var additionalImports: List<Symbol> = emptyList()
146151

152+
var order: Int = 0
153+
147154
fun build(): ClientConfigProperty = ClientConfigProperty(this)
148155
}
149156
}
@@ -237,6 +244,7 @@ object KotlinClientRuntimeConfigProperty {
237244
NOTE: The caller is responsible for managing the lifetime of the engine when set. The SDK
238245
client will not close it when the client is closed.
239246
""".trimIndent()
247+
order = -100
240248
}
241249

242250
IdempotencyTokenProvider = ClientConfigProperty {

smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/ClientConfigGeneratorTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public class Config private constructor(builder: Builder): HttpClientConfig, Ide
4040
contents.shouldContainWithDiff(expectedCtor)
4141

4242
val expectedProps = """
43-
public val endpointResolver: EndpointResolver = requireNotNull(builder.endpointResolver) { "endpointResolver is a required configuration property" }
4443
override val httpClientEngine: HttpClientEngine? = builder.httpClientEngine
44+
public val endpointResolver: EndpointResolver = requireNotNull(builder.endpointResolver) { "endpointResolver is a required configuration property" }
4545
override val idempotencyTokenProvider: IdempotencyTokenProvider? = builder.idempotencyTokenProvider
4646
public val retryStrategy: RetryStrategy = builder.retryStrategy ?: StandardRetryStrategy()
4747
override val sdkLogMode: SdkLogMode = builder.sdkLogMode
@@ -50,17 +50,17 @@ public class Config private constructor(builder: Builder): HttpClientConfig, Ide
5050

5151
val expectedBuilder = """
5252
public class Builder {
53-
/**
54-
* Set the [aws.smithy.kotlin.runtime.http.endpoints.EndpointResolver] used to resolve service endpoints. Operation requests will be
55-
* made against the endpoint returned by the resolver.
56-
*/
57-
public var endpointResolver: EndpointResolver? = null
5853
/**
5954
* Override the default HTTP client engine used to make SDK requests (e.g. configure proxy behavior, timeouts, concurrency, etc).
6055
* NOTE: The caller is responsible for managing the lifetime of the engine when set. The SDK
6156
* client will not close it when the client is closed.
6257
*/
6358
public var httpClientEngine: HttpClientEngine? = null
59+
/**
60+
* Set the [aws.smithy.kotlin.runtime.http.endpoints.EndpointResolver] used to resolve service endpoints. Operation requests will be
61+
* made against the endpoint returned by the resolver.
62+
*/
63+
public var endpointResolver: EndpointResolver? = null
6464
/**
6565
* Override the default idempotency token generator. SDK clients will generate tokens for members
6666
* that represent idempotent tokens when not explicitly set by the caller using this generator.

0 commit comments

Comments
 (0)