Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0.

public struct OperationStack<OperationStackInput: Encodable & Reflection,
public struct OperationStack<OperationStackInput,
OperationStackOutput: HttpResponseBinding,
OperationStackError: HttpResponseBinding> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// Takes Input Parameters, and returns result or error.
///
/// Receives result or error from Serialize step.
public typealias InitializeStep<I: Encodable & Reflection,
public typealias InitializeStep<I,
O: HttpResponseBinding,
E: HttpResponseBinding> = MiddlewareStep<HttpContext,
I,
Expand All @@ -16,7 +16,7 @@ public typealias InitializeStep<I: Encodable & Reflection,

public let InitializeStepId = "Initialize"

public struct InitializeStepHandler<OperationStackInput: Encodable & Reflection,
public struct InitializeStepHandler<OperationStackInput,
OperationStackOutput: HttpResponseBinding,
OperationStackError: HttpResponseBinding,
H: Handler>: Handler where H.Context == HttpContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// Converts Input Parameters into a Request, and returns the result or error.
///
/// Receives result or error from Build step.
public typealias SerializeStep<I: Encodable & Reflection,
public typealias SerializeStep<I,
O: HttpResponseBinding,
E: HttpResponseBinding> = MiddlewareStep<HttpContext,
SerializeStepInput<I>,
Expand All @@ -16,7 +16,7 @@ public typealias SerializeStep<I: Encodable & Reflection,

public let SerializeStepId = "Serialize"

public struct SerializeStepHandler<OperationStackInput: Encodable & Reflection,
public struct SerializeStepHandler<OperationStackInput,
OperationStackOutput: HttpResponseBinding,
OperationStackError: HttpResponseBinding,
H: Handler>: Handler where H.Context == HttpContext,
Expand All @@ -41,7 +41,7 @@ public struct SerializeStepHandler<OperationStackInput: Encodable & Reflection,
}
}

public struct SerializeStepInput<OperationStackInput: Encodable & Reflection> {
public struct SerializeStepInput<OperationStackInput> {
public let operationInput: OperationStackInput
public let builder: SdkHttpRequestBuilder = SdkHttpRequestBuilder()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0.

public struct ContentTypeMiddleware<OperationStackInput: Encodable & Reflection,
public struct ContentTypeMiddleware<OperationStackInput,
OperationStackOutput: HttpResponseBinding,
OperationStackError: HttpResponseBinding>: Middleware {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
//

public struct HeaderMiddleware<OperationStackInput: Encodable & Reflection & HeaderProvider,
public struct HeaderMiddleware<OperationStackInput: HeaderProvider,
OperationStackOutput: HttpResponseBinding,
OperationStackError: HttpResponseBinding>: Middleware {
public let id: String = "\(String(describing: OperationStackInput.self))HeadersMiddleware"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
//

public struct QueryItemMiddleware<OperationStackInput: Encodable & Reflection & QueryItemProvider,
public struct QueryItemMiddleware<OperationStackInput: QueryItemProvider,
OperationStackOutput: HttpResponseBinding,
OperationStackError: HttpResponseBinding>: Middleware {
public let id: String = "\(String(describing: OperationStackInput.self))QueryItemMiddleware"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
//

public struct URLHostMiddleware<OperationStackInput: Encodable & Reflection,
public struct URLHostMiddleware<OperationStackInput,
OperationStackOutput: HttpResponseBinding,
OperationStackError: HttpResponseBinding>: Middleware {
public let id: String = "\(String(describing: OperationStackInput.self))URLHostMiddleware"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
//

public struct URLPathMiddleware<OperationStackInput: Encodable & Reflection & URLPathProvider,
public struct URLPathMiddleware<OperationStackInput: URLPathProvider,
OperationStackOutput: HttpResponseBinding,
OperationStackError: HttpResponseBinding>: ClientRuntime.Middleware {
public let id: Swift.String = "\(String(describing: OperationStackInput.self))URLPathMiddleware"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ class StructureGenerator(
writer.write("self.\$1L = \$1L", memberName)
}
}
} else {
writer.write("public init() {}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,22 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
val httpBodyMembers = shape.members()
.filter { it.isInHttpBody() }
.toList()
ctx.delegator.useShapeWriter(encodeSymbol) { writer ->
writer.openBlock("extension $symbolName: \$N, \$N {", "}", SwiftTypes.Protocols.Encodable, ClientRuntimeTypes.Core.Reflection) {
writer.addImport(SwiftDependency.CLIENT_RUNTIME.target)

if (shouldRenderCodingKeysForEncodable) {
generateCodingKeysForMembers(ctx, writer, httpBodyMembers)
writer.write("")
if (httpBodyMembers.isNotEmpty() || shouldRenderEncodableConformance) {
ctx.delegator.useShapeWriter(encodeSymbol) { writer ->
writer.openBlock(
"extension $symbolName: \$N, \$N {",
"}",
SwiftTypes.Protocols.Encodable,
ClientRuntimeTypes.Core.Reflection
) {
writer.addImport(SwiftDependency.CLIENT_RUNTIME.target)

if (shouldRenderCodingKeysForEncodable) {
generateCodingKeysForMembers(ctx, writer, httpBodyMembers)
writer.write("")
}
renderStructEncode(ctx, shape, shapeMetadata, httpBodyMembers, writer, defaultTimestampFormat)
}
renderStructEncode(ctx, shape, shapeMetadata, httpBodyMembers, writer, defaultTimestampFormat)
}
}
if (shouldRenderDecodableBodyStructForInputShapes && httpBodyMembers.isNotEmpty()) {
Expand All @@ -173,9 +180,12 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
httpResponseGenerator.render(ctx, httpOperations, httpBindingResolver)

val outputShapesWithMetadata = resolveOutputShapes(ctx)

for ((shape, metadata) in outputShapesWithMetadata) {
renderBodyStructAndDecodableExtension(ctx, shape, metadata)
DynamicNodeDecodingGeneratorStrategy(ctx, shape, isForBodyStruct = true).renderIfNeeded()
if (shape.members().any { it.isInHttpBody() }) {
renderBodyStructAndDecodableExtension(ctx, shape, metadata)
DynamicNodeDecodingGeneratorStrategy(ctx, shape, isForBodyStruct = true).renderIfNeeded()
}
}

val errorShapes = resolveErrorShapes(ctx)
Expand Down Expand Up @@ -410,6 +420,7 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
protected abstract val httpResponseGenerator: HttpResponseGeneratable
protected abstract val shouldRenderDecodableBodyStructForInputShapes: Boolean
protected abstract val shouldRenderCodingKeysForEncodable: Boolean
protected abstract val shouldRenderEncodableConformance: Boolean
protected abstract fun renderStructEncode(
ctx: ProtocolGenerator.GenerationContext,
shapeContainingMembers: Shape,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ class HttpResponseBindingOutputGenerator(
ctx.delegator.useShapeWriter(httpBindingSymbol) { writer ->
writer.addImport(SwiftDependency.CLIENT_RUNTIME.target)
writer.openBlock("extension $outputShapeName: \$N {", "}", ClientRuntimeTypes.Http.HttpResponseBinding) {
writer.openBlock("public init (httpResponse: \$N, decoder: \$D) throws {", "}", ClientRuntimeTypes.Http.HttpResponse, ClientRuntimeTypes.Serde.ResponseDecoder) {
writer.openBlock(
"public init (httpResponse: \$N, decoder: \$D) throws {",
"}",
ClientRuntimeTypes.Http.HttpResponse,
ClientRuntimeTypes.Serde.ResponseDecoder
) {
HttpResponseHeaders(ctx, headerBindings, defaultTimestampFormat, writer).render()
HttpResponsePrefixHeaders(ctx, responseBindings, writer).render()
HttpResponseTraitPayload(ctx, responseBindings, outputShapeName, writer).render()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class MockHttpAWSJson11ProtocolGenerator : HttpBindingProtocolGenerator() {
)
override val shouldRenderDecodableBodyStructForInputShapes = true
override val shouldRenderCodingKeysForEncodable = true
override val shouldRenderEncodableConformance = false

override fun renderStructEncode(
ctx: ProtocolGenerator.GenerationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class MockHttpEC2QueryProtocolGenerator : HttpBindingProtocolGenerator() {
)
override val shouldRenderDecodableBodyStructForInputShapes = false
override val shouldRenderCodingKeysForEncodable = false
override val shouldRenderEncodableConformance = true
override fun renderStructEncode(
ctx: ProtocolGenerator.GenerationContext,
shapeContainingMembers: Shape,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MockHttpRestJsonProtocolGenerator : HttpBindingProtocolGenerator() {
)
override val shouldRenderDecodableBodyStructForInputShapes = true
override val shouldRenderCodingKeysForEncodable = true
override val shouldRenderEncodableConformance = false

override fun renderStructEncode(
ctx: ProtocolGenerator.GenerationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MockHttpRestXMLProtocolGenerator : HttpBindingProtocolGenerator() {
)
override val shouldRenderDecodableBodyStructForInputShapes = true
override val shouldRenderCodingKeysForEncodable = true
override val shouldRenderEncodableConformance = false

override fun renderStructEncode(
ctx: ProtocolGenerator.GenerationContext,
Expand Down