Skip to content

Commit aa0fcfb

Browse files
authored
fix: Streamline HttpInterceptor type inference (#813)
1 parent 146b5b7 commit aa0fcfb

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
lines changed

Sources/ClientRuntime/Interceptor/HttpInterceptorProvider.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
import class SmithyHTTPAPI.HTTPRequest
9+
import class SmithyHTTPAPI.HTTPResponse
10+
811
/// Provides implementations of `HttpInterceptor`.
912
///
1013
/// For the generic counterpart, see `InterceptorProvider`.
@@ -13,5 +16,5 @@ public protocol HttpInterceptorProvider {
1316
/// Creates an instance of an `HttpInterceptor` implementation.
1417
///
1518
/// - Returns: The `HttpInterceptor` implementation.
16-
func create<InputType, OutputType>() -> any HttpInterceptor<InputType, OutputType>
19+
func create<InputType, OutputType>() -> any Interceptor<InputType, OutputType, HTTPRequest, HTTPResponse>
1720
}

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,11 @@ class MiddlewareExecutionGenerator(
5151
SmithyHTTPAPITypes.HTTPRequest,
5252
SmithyHTTPAPITypes.HTTPResponse,
5353
)
54-
writer.write(
55-
"""
56-
config.interceptorProviders.forEach { provider in
57-
builder.interceptors.add(provider.create())
58-
}
59-
""".trimIndent()
60-
)
61-
writer.openBlock(
62-
"config.httpInterceptorProviders.forEach { (provider: any \$N) -> Void in",
63-
"}",
64-
ClientRuntimeTypes.Core.HttpInterceptorProvider,
65-
) {
66-
writer.write(
67-
"let i: any \$N<\$N, \$N> = provider.create()",
68-
ClientRuntimeTypes.Core.HttpInterceptor,
69-
inputShape,
70-
outputShape,
71-
)
72-
writer.write("builder.interceptors.add(i)")
54+
writer.openBlock("config.interceptorProviders.forEach { provider in", "}") {
55+
writer.write("builder.interceptors.add(provider.create())")
56+
}
57+
writer.openBlock("config.httpInterceptorProviders.forEach { provider in", "}") {
58+
writer.write("builder.interceptors.add(provider.create())")
7359
}
7460

7561
renderMiddlewares(ctx, op, operationStackName)

smithy-swift-codegen/src/test/kotlin/EventStreamTests.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ extension EventStreamTestClientTypes.TestStream {
218218
config.interceptorProviders.forEach { provider in
219219
builder.interceptors.add(provider.create())
220220
}
221-
config.httpInterceptorProviders.forEach { (provider: any ClientRuntime.HttpInterceptorProvider) -> Void in
222-
let i: any ClientRuntime.HttpInterceptor<TestStreamOpInput, TestStreamOpOutput> = provider.create()
223-
builder.interceptors.add(i)
221+
config.httpInterceptorProviders.forEach { provider in
222+
builder.interceptors.add(provider.create())
224223
}
225224
builder.interceptors.add(ClientRuntime.URLPathMiddleware<TestStreamOpInput, TestStreamOpOutput>(TestStreamOpInput.urlPathProvider(_:)))
226225
builder.interceptors.add(ClientRuntime.URLHostMiddleware<TestStreamOpInput, TestStreamOpOutput>())

smithy-swift-codegen/src/test/kotlin/HttpProtocolClientGeneratorTests.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ extension RestJsonProtocolClient {
158158
config.interceptorProviders.forEach { provider in
159159
builder.interceptors.add(provider.create())
160160
}
161-
config.httpInterceptorProviders.forEach { (provider: any ClientRuntime.HttpInterceptorProvider) -> Void in
162-
let i: any ClientRuntime.HttpInterceptor<AllocateWidgetInput, AllocateWidgetOutput> = provider.create()
163-
builder.interceptors.add(i)
161+
config.httpInterceptorProviders.forEach { provider in
162+
builder.interceptors.add(provider.create())
164163
}
165164
builder.interceptors.add(ClientRuntime.IdempotencyTokenMiddleware<AllocateWidgetInput, AllocateWidgetOutput>(keyPath: \.clientToken))
166165
builder.interceptors.add(ClientRuntime.URLPathMiddleware<AllocateWidgetInput, AllocateWidgetOutput>(AllocateWidgetInput.urlPathProvider(_:)))

0 commit comments

Comments
 (0)