Skip to content

Commit 757c01b

Browse files
authored
feat: Implement GET presigner for synthesizespeech (#354)
1 parent 0db400c commit 757c01b

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

Packages/ClientRuntime/Sources/PrimitiveTypeExtensions/URL+Extension.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import Foundation
7+
public typealias URL = Foundation.URL
78
extension URL {
89
func toQueryItems() -> [URLQueryItem]? { return URLComponents(url: self,
910
resolvingAgainstBaseURL: false)?.queryItems }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ object ClientRuntimeTypes {
6969
val Data = runtimeSymbol("Data")
7070
val Document = runtimeSymbol("Document")
7171
val URLQueryItem = runtimeSymbol("URLQueryItem")
72+
val URL = runtimeSymbol("URL")
7273
val ClientError = runtimeSymbol("ClientError")
7374
val SdkError = runtimeSymbol("SdkError")
7475
val ServiceError = runtimeSymbol("ServiceError")

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/middleware/MiddlewareExecutionGenerator.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ import software.amazon.smithy.swift.codegen.model.camelCaseName
1515
import software.amazon.smithy.swift.codegen.model.capitalizedName
1616
import software.amazon.smithy.swift.codegen.swiftFunctionParameterIndent
1717

18+
typealias HttpMethodCallback = () -> String
1819
class MiddlewareExecutionGenerator(
1920
private val ctx: ProtocolGenerator.GenerationContext,
2021
private val writer: SwiftWriter,
2122
private val httpBindingResolver: HttpBindingResolver,
2223
private val httpProtocolCustomizable: HttpProtocolCustomizable,
2324
private val operationMiddleware: OperationMiddleware,
2425
private val operationStackName: String,
25-
private val executionContext: MiddlewareRenderableExecutionContext
26+
private val executionContext: MiddlewareRenderableExecutionContext,
27+
private val httpMethodCallback: HttpMethodCallback? = null
2628
) {
2729
private val model: Model = ctx.model
2830
private val symbolProvider = ctx.symbolProvider
@@ -40,8 +42,8 @@ class MiddlewareExecutionGenerator(
4042
}
4143

4244
private fun renderContextAttributes(op: OperationShape) {
43-
val httpTrait = httpBindingResolver.httpTrait(op)
44-
val httpMethod = httpTrait.method.toLowerCase()
45+
val httpMethod = resolveHttpMethod(op)
46+
4547
// FIXME it over indents if i add another indent, come up with better way to properly indent or format for swift
4648
writer.write(" .withEncoder(value: encoder)")
4749
writer.write(" .withDecoder(value: decoder)")
@@ -60,6 +62,15 @@ class MiddlewareExecutionGenerator(
6062
httpProtocolCustomizable.renderContextAttributes(ctx, writer, serviceShape, op)
6163
}
6264

65+
private fun resolveHttpMethod(op: OperationShape): String {
66+
return httpMethodCallback?.let {
67+
it()
68+
} ?: run {
69+
val httpTrait = httpBindingResolver.httpTrait(op)
70+
httpTrait.method.toLowerCase()
71+
}
72+
}
73+
6374
private fun renderMiddlewares(op: OperationShape, operationStackName: String) {
6475
operationMiddleware.renderMiddleware(ctx.model, ctx.symbolProvider, writer, op, operationStackName, MiddlewareStep.INITIALIZESTEP, executionContext)
6576
operationMiddleware.renderMiddleware(ctx.model, ctx.symbolProvider, writer, op, operationStackName, MiddlewareStep.BUILDSTEP, executionContext)

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/middleware/OperationMiddleware.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface OperationMiddleware {
1010
fun prependMiddleware(operation: OperationShape, renderableMiddleware: MiddlewareRenderable)
1111
fun removeMiddleware(operation: OperationShape, step: MiddlewareStep, middlewareName: String)
1212

13+
fun clone(): OperationMiddleware
14+
1315
fun renderMiddleware(
1416
model: Model,
1517
symbolProvider: SymbolProvider,

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/middleware/OperationMiddlewareGenerator.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import software.amazon.smithy.model.Model
55
import software.amazon.smithy.model.shapes.OperationShape
66
import software.amazon.smithy.swift.codegen.SwiftWriter
77

8-
open class OperationMiddlewareGenerator : OperationMiddleware {
8+
open class OperationMiddlewareGenerator(val mutableHashMap: MutableMap<OperationShape, MiddlewareStack> = mutableMapOf()) : OperationMiddleware {
99

10-
private var middlewareMap: MutableMap<OperationShape, MiddlewareStack> = mutableMapOf()
10+
private var middlewareMap: MutableMap<OperationShape, MiddlewareStack> = mutableHashMap
1111

1212
override fun appendMiddleware(operation: OperationShape, renderableMiddleware: MiddlewareRenderable) {
1313
val step = renderableMiddleware.middlewareStep
@@ -28,6 +28,20 @@ open class OperationMiddlewareGenerator : OperationMiddleware {
2828
}
2929
}
3030

31+
override fun clone(): OperationMiddleware {
32+
val copy: MutableMap<OperationShape, MiddlewareStack> = mutableMapOf()
33+
middlewareMap.forEach { (shape, stack) ->
34+
copy[shape] = MiddlewareStack(
35+
stack.initializeMiddlewares.toMutableList(),
36+
stack.serializeMiddlewares.toMutableList(),
37+
stack.buildMiddlewares.toMutableList(),
38+
stack.finalizeMiddlewares.toMutableList(),
39+
stack.deserializeMiddlewares.toMutableList()
40+
)
41+
}
42+
return OperationMiddlewareGenerator(copy)
43+
}
44+
3145
override fun renderMiddleware(
3246
model: Model,
3347
symbolProvider: SymbolProvider,

0 commit comments

Comments
 (0)