55package software.amazon.smithy.kotlin.codegen.rendering
66
77import software.amazon.smithy.codegen.core.Symbol
8- import software.amazon.smithy.codegen.core.SymbolReference
98import software.amazon.smithy.kotlin.codegen.core.*
109import software.amazon.smithy.kotlin.codegen.model.boxed
1110import software.amazon.smithy.kotlin.codegen.model.buildSymbol
@@ -59,14 +58,17 @@ class ClientConfigProperty private constructor(builder: Builder) {
5958 val baseClass: Symbol ? = builder.baseClass
6059
6160 /* *
62- * If the property is not provided in the builder then a ClientException is thrown
61+ * The configuration property type. This controls how the property is constructed and rendered
6362 */
64- val required : Boolean = builder.required
63+ val propertyType : ClientConfigPropertyType = builder.propertyType
6564
6665 /* *
67- * Specifies that the value should be populated with a constant value that cannot be overridden in the builder.
66+ * Additional symbols that should be imported when this property is generated. This is useful for
67+ * example when the [symbol] type has is an interface and has a default or constant value that
68+ * implements that type. The default value symbol also needs imported.
6869 */
69- val constantValue: String? = builder.constantValue
70+ val additionalImports: List <Symbol > = builder.additionalImports
71+
7072 /* *
7173 * Flag indicating if this property stems from some base class and needs an override modifier when rendered
7274 */
@@ -90,7 +92,7 @@ class ClientConfigProperty private constructor(builder: Builder) {
9092 name : String ,
9193 defaultValue : Int? = null,
9294 documentation : String? = null,
93- baseClass : Symbol ? = null
95+ baseClass : Symbol ? = null,
9496 ): ClientConfigProperty =
9597 builtInProperty(name, builtInSymbol(" Int" , defaultValue?.toString()), documentation, baseClass)
9698
@@ -107,7 +109,7 @@ class ClientConfigProperty private constructor(builder: Builder) {
107109 name : String ,
108110 defaultValue : Boolean? = null,
109111 documentation : String? = null,
110- baseClass : Symbol ? = null
112+ baseClass : Symbol ? = null,
111113 ): ClientConfigProperty =
112114 builtInProperty(name, builtInSymbol(" Boolean" , defaultValue?.toString()), documentation, baseClass)
113115
@@ -124,7 +126,7 @@ class ClientConfigProperty private constructor(builder: Builder) {
124126 name : String ,
125127 defaultValue : String? = null,
126128 documentation : String? = null,
127- baseClass : Symbol ? = null
129+ baseClass : Symbol ? = null,
128130 ): ClientConfigProperty =
129131 builtInProperty(name, builtInSymbol(" String" , defaultValue), documentation, baseClass)
130132 }
@@ -137,13 +139,49 @@ class ClientConfigProperty private constructor(builder: Builder) {
137139
138140 var baseClass: Symbol ? = null
139141
140- var required: Boolean = false
141- var constantValue: String? = null
142+ var propertyType: ClientConfigPropertyType = ClientConfigPropertyType .SymbolDefault
143+
144+ var additionalImports: List <Symbol > = emptyList()
142145
143146 fun build (): ClientConfigProperty = ClientConfigProperty (this )
144147 }
145148}
146149
150+ /* *
151+ * Descriptor for how a configuration property is rendered when the configuration is built
152+ */
153+ sealed class ClientConfigPropertyType {
154+ /* *
155+ * A property type that uses the symbol type and builder symbol directly
156+ */
157+ object SymbolDefault : ClientConfigPropertyType()
158+
159+ /* *
160+ * Specifies that the value should be populated with a constant value that cannot be overridden in the builder.
161+ * These are effectively read-only properties that will show up in the configuration type but not the builder.
162+ *
163+ * @param value the value to assign to the property at construction time
164+ */
165+ data class ConstantValue (val value : String ) : ClientConfigPropertyType()
166+
167+ /* *
168+ * A configuration property that is required to be set (i.e. not null).
169+ * If the property is not provided in the builder then an IllegalArgumentException is thrown
170+ *
171+ * @param message The exception message to throw if the property is null, if not set a message is generated
172+ * automatically based on the property name
173+ */
174+ data class Required (val message : String? = null ) : ClientConfigPropertyType()
175+
176+ /* *
177+ * A configuration property that is required but has a default value. This has the same semantics of [Required]
178+ * but instead of an exception the default value will be used when not provided in the builder.
179+ *
180+ * @param default the value to assign if the corresponding builder property is null
181+ */
182+ data class RequiredWithDefault (val default : String ) : ClientConfigPropertyType()
183+ }
184+
147185private fun builtInSymbol (symbolName : String , defaultValue : String? ): Symbol {
148186 val builder = Symbol .builder()
149187 .name(symbolName)
@@ -156,7 +194,12 @@ private fun builtInSymbol(symbolName: String, defaultValue: String?): Symbol {
156194 return builder.build()
157195}
158196
159- private fun builtInProperty (name : String , symbol : Symbol , documentation : String? , baseClass : Symbol ? ): ClientConfigProperty =
197+ private fun builtInProperty (
198+ name : String ,
199+ symbol : Symbol ,
200+ documentation : String? ,
201+ baseClass : Symbol ? ,
202+ ): ClientConfigProperty =
160203 ClientConfigProperty {
161204 this .symbol = symbol
162205 this .name = name
@@ -180,13 +223,10 @@ object KotlinClientRuntimeConfigProperty {
180223 }
181224
182225 HttpClientEngine = ClientConfigProperty {
183- symbol = buildSymbol {
184- name = " HttpClientEngine"
185- namespace(KotlinDependency .HTTP , " engine" )
186- }
226+ symbol = RuntimeTypes .Http .Engine .HttpClientEngine
187227 baseClass = httpClientConfigSymbol
188228 documentation = """
189- Override the default HTTP client configuration (e.g. configure proxy behavior, concurrency, etc)
229+ Override the default HTTP client engine used to make SDK requests (e.g. configure proxy behavior, timeouts , concurrency, etc)
190230 """ .trimIndent()
191231 }
192232
@@ -208,6 +248,13 @@ object KotlinClientRuntimeConfigProperty {
208248 }
209249
210250 RetryStrategy = ClientConfigProperty {
251+ symbol = RuntimeTypes .Core .Retries .RetryStrategy
252+ name = " retryStrategy"
253+ documentation = """
254+ The [RetryStrategy] implementation to use for service calls. All API calls will be wrapped by the
255+ strategy.
256+ """ .trimIndent()
257+
211258 val retryStrategyBlock = """
212259 run {
213260 val strategyOptions = StandardRetryStrategyOptions.Default
@@ -216,24 +263,16 @@ object KotlinClientRuntimeConfigProperty {
216263 StandardRetryStrategy(strategyOptions, tokenBucket, delayer)
217264 }
218265 """ .trimIndent()
219-
220- symbol = buildSymbol {
221- name = " RetryStrategy"
222- namespace(KotlinDependency .CORE , " retries" )
223- nullable = false
224- reference(RuntimeTypes .Core .Retries .Impl .StandardRetryStrategy , SymbolReference .ContextOption .USE )
225- reference(RuntimeTypes .Core .Retries .Impl .StandardRetryStrategyOptions , SymbolReference .ContextOption .USE )
226- reference(RuntimeTypes .Core .Retries .Impl .StandardRetryTokenBucket , SymbolReference .ContextOption .USE )
227- reference(RuntimeTypes .Core .Retries .Impl .StandardRetryTokenBucketOptions , SymbolReference .ContextOption .USE )
228- reference(RuntimeTypes .Core .Retries .Impl .ExponentialBackoffWithJitter , SymbolReference .ContextOption .USE )
229- reference(RuntimeTypes .Core .Retries .Impl .ExponentialBackoffWithJitterOptions , SymbolReference .ContextOption .USE )
230- }
231- name = " retryStrategy"
232- documentation = """
233- The [RetryStrategy] implementation to use for service calls. All API calls will be wrapped by the
234- strategy.
235- """ .trimIndent()
236- constantValue = retryStrategyBlock
266+ propertyType = ClientConfigPropertyType .ConstantValue (retryStrategyBlock)
267+
268+ additionalImports = listOf (
269+ RuntimeTypes .Core .Retries .Impl .StandardRetryStrategy ,
270+ RuntimeTypes .Core .Retries .Impl .StandardRetryStrategyOptions ,
271+ RuntimeTypes .Core .Retries .Impl .StandardRetryTokenBucket ,
272+ RuntimeTypes .Core .Retries .Impl .StandardRetryTokenBucketOptions ,
273+ RuntimeTypes .Core .Retries .Impl .ExponentialBackoffWithJitter ,
274+ RuntimeTypes .Core .Retries .Impl .ExponentialBackoffWithJitterOptions ,
275+ )
237276 }
238277
239278 SdkLogMode = ClientConfigProperty {
0 commit comments