Skip to content

Commit 158bf51

Browse files
authored
fix: remove unnecessary protocol conformance (#404)
1 parent acbd30c commit 158bf51

File tree

15 files changed

+42
-24
lines changed

15 files changed

+42
-24
lines changed

Packages/ClientRuntime/Sources/Middleware/OperationStack.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0.
33

4-
public struct OperationStack<OperationStackInput: Encodable & Reflection,
4+
public struct OperationStack<OperationStackInput,
55
OperationStackOutput: HttpResponseBinding,
66
OperationStackError: HttpResponseBinding> {
77

Packages/ClientRuntime/Sources/Middleware/Steps/InitializeStep.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// Takes Input Parameters, and returns result or error.
88
///
99
/// Receives result or error from Serialize step.
10-
public typealias InitializeStep<I: Encodable & Reflection,
10+
public typealias InitializeStep<I,
1111
O: HttpResponseBinding,
1212
E: HttpResponseBinding> = MiddlewareStep<HttpContext,
1313
I,
@@ -16,7 +16,7 @@ public typealias InitializeStep<I: Encodable & Reflection,
1616

1717
public let InitializeStepId = "Initialize"
1818

19-
public struct InitializeStepHandler<OperationStackInput: Encodable & Reflection,
19+
public struct InitializeStepHandler<OperationStackInput,
2020
OperationStackOutput: HttpResponseBinding,
2121
OperationStackError: HttpResponseBinding,
2222
H: Handler>: Handler where H.Context == HttpContext,

Packages/ClientRuntime/Sources/Middleware/Steps/SerializeStep.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// Converts Input Parameters into a Request, and returns the result or error.
88
///
99
/// Receives result or error from Build step.
10-
public typealias SerializeStep<I: Encodable & Reflection,
10+
public typealias SerializeStep<I,
1111
O: HttpResponseBinding,
1212
E: HttpResponseBinding> = MiddlewareStep<HttpContext,
1313
SerializeStepInput<I>,
@@ -16,7 +16,7 @@ public typealias SerializeStep<I: Encodable & Reflection,
1616

1717
public let SerializeStepId = "Serialize"
1818

19-
public struct SerializeStepHandler<OperationStackInput: Encodable & Reflection,
19+
public struct SerializeStepHandler<OperationStackInput,
2020
OperationStackOutput: HttpResponseBinding,
2121
OperationStackError: HttpResponseBinding,
2222
H: Handler>: Handler where H.Context == HttpContext,
@@ -41,7 +41,7 @@ public struct SerializeStepHandler<OperationStackInput: Encodable & Reflection,
4141
}
4242
}
4343

44-
public struct SerializeStepInput<OperationStackInput: Encodable & Reflection> {
44+
public struct SerializeStepInput<OperationStackInput> {
4545
public let operationInput: OperationStackInput
4646
public let builder: SdkHttpRequestBuilder = SdkHttpRequestBuilder()
4747
}

Packages/ClientRuntime/Sources/Networking/Http/Middlewares/ContentTypeMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0.
33

4-
public struct ContentTypeMiddleware<OperationStackInput: Encodable & Reflection,
4+
public struct ContentTypeMiddleware<OperationStackInput,
55
OperationStackOutput: HttpResponseBinding,
66
OperationStackError: HttpResponseBinding>: Middleware {
77

Packages/ClientRuntime/Sources/Networking/Http/Middlewares/HeaderMiddleware.swift

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

8-
public struct HeaderMiddleware<OperationStackInput: Encodable & Reflection & HeaderProvider,
8+
public struct HeaderMiddleware<OperationStackInput: HeaderProvider,
99
OperationStackOutput: HttpResponseBinding,
1010
OperationStackError: HttpResponseBinding>: Middleware {
1111
public let id: String = "\(String(describing: OperationStackInput.self))HeadersMiddleware"

Packages/ClientRuntime/Sources/Networking/Http/Middlewares/QueryItemMiddleware.swift

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

8-
public struct QueryItemMiddleware<OperationStackInput: Encodable & Reflection & QueryItemProvider,
8+
public struct QueryItemMiddleware<OperationStackInput: QueryItemProvider,
99
OperationStackOutput: HttpResponseBinding,
1010
OperationStackError: HttpResponseBinding>: Middleware {
1111
public let id: String = "\(String(describing: OperationStackInput.self))QueryItemMiddleware"

Packages/ClientRuntime/Sources/Networking/Http/Middlewares/URLHostMiddleware.swift

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

8-
public struct URLHostMiddleware<OperationStackInput: Encodable & Reflection,
8+
public struct URLHostMiddleware<OperationStackInput,
99
OperationStackOutput: HttpResponseBinding,
1010
OperationStackError: HttpResponseBinding>: Middleware {
1111
public let id: String = "\(String(describing: OperationStackInput.self))URLHostMiddleware"

Packages/ClientRuntime/Sources/Networking/Http/Middlewares/URLPathMiddleware.swift

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

8-
public struct URLPathMiddleware<OperationStackInput: Encodable & Reflection & URLPathProvider,
8+
public struct URLPathMiddleware<OperationStackInput: URLPathProvider,
99
OperationStackOutput: HttpResponseBinding,
1010
OperationStackError: HttpResponseBinding>: ClientRuntime.Middleware {
1111
public let id: Swift.String = "\(String(describing: OperationStackInput.self))URLPathMiddleware"

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ class StructureGenerator(
149149
writer.write("self.\$1L = \$1L", memberName)
150150
}
151151
}
152-
} else {
153-
writer.write("public init() {}")
154152
}
155153
}
156154

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,22 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
149149
val httpBodyMembers = shape.members()
150150
.filter { it.isInHttpBody() }
151151
.toList()
152-
ctx.delegator.useShapeWriter(encodeSymbol) { writer ->
153-
writer.openBlock("extension $symbolName: \$N, \$N {", "}", SwiftTypes.Protocols.Encodable, ClientRuntimeTypes.Core.Reflection) {
154-
writer.addImport(SwiftDependency.CLIENT_RUNTIME.target)
155-
156-
if (shouldRenderCodingKeysForEncodable) {
157-
generateCodingKeysForMembers(ctx, writer, httpBodyMembers)
158-
writer.write("")
152+
if (httpBodyMembers.isNotEmpty() || shouldRenderEncodableConformance) {
153+
ctx.delegator.useShapeWriter(encodeSymbol) { writer ->
154+
writer.openBlock(
155+
"extension $symbolName: \$N, \$N {",
156+
"}",
157+
SwiftTypes.Protocols.Encodable,
158+
ClientRuntimeTypes.Core.Reflection
159+
) {
160+
writer.addImport(SwiftDependency.CLIENT_RUNTIME.target)
161+
162+
if (shouldRenderCodingKeysForEncodable) {
163+
generateCodingKeysForMembers(ctx, writer, httpBodyMembers)
164+
writer.write("")
165+
}
166+
renderStructEncode(ctx, shape, shapeMetadata, httpBodyMembers, writer, defaultTimestampFormat)
159167
}
160-
renderStructEncode(ctx, shape, shapeMetadata, httpBodyMembers, writer, defaultTimestampFormat)
161168
}
162169
}
163170
if (shouldRenderDecodableBodyStructForInputShapes && httpBodyMembers.isNotEmpty()) {
@@ -173,9 +180,12 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
173180
httpResponseGenerator.render(ctx, httpOperations, httpBindingResolver)
174181

175182
val outputShapesWithMetadata = resolveOutputShapes(ctx)
183+
176184
for ((shape, metadata) in outputShapesWithMetadata) {
177-
renderBodyStructAndDecodableExtension(ctx, shape, metadata)
178-
DynamicNodeDecodingGeneratorStrategy(ctx, shape, isForBodyStruct = true).renderIfNeeded()
185+
if (shape.members().any { it.isInHttpBody() }) {
186+
renderBodyStructAndDecodableExtension(ctx, shape, metadata)
187+
DynamicNodeDecodingGeneratorStrategy(ctx, shape, isForBodyStruct = true).renderIfNeeded()
188+
}
179189
}
180190

181191
val errorShapes = resolveErrorShapes(ctx)
@@ -410,6 +420,7 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
410420
protected abstract val httpResponseGenerator: HttpResponseGeneratable
411421
protected abstract val shouldRenderDecodableBodyStructForInputShapes: Boolean
412422
protected abstract val shouldRenderCodingKeysForEncodable: Boolean
423+
protected abstract val shouldRenderEncodableConformance: Boolean
413424
protected abstract fun renderStructEncode(
414425
ctx: ProtocolGenerator.GenerationContext,
415426
shapeContainingMembers: Shape,

0 commit comments

Comments
 (0)