diff --git a/smithy-swift-codegen-test-utils/src/main/kotlin/software/amazon/smithy/swift/codegen/test/utils/TestProtocolGenerator.kt b/smithy-swift-codegen-test-utils/src/main/kotlin/software/amazon/smithy/swift/codegen/test/utils/TestProtocolGenerator.kt index 024fc6b1e..c5f18d90c 100644 --- a/smithy-swift-codegen-test-utils/src/main/kotlin/software/amazon/smithy/swift/codegen/test/utils/TestProtocolGenerator.kt +++ b/smithy-swift-codegen-test-utils/src/main/kotlin/software/amazon/smithy/swift/codegen/test/utils/TestProtocolGenerator.kt @@ -5,11 +5,8 @@ package software.amazon.smithy.swift.codegen.test.utils -import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.swift.codegen.SwiftWriter import software.amazon.smithy.swift.codegen.integration.DefaultHTTPProtocolCustomizations import software.amazon.smithy.swift.codegen.integration.DefaultServiceConfig @@ -23,10 +20,7 @@ import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestRequ import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestResponseGenerator import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator import software.amazon.smithy.swift.codegen.integration.ServiceConfig -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructDecodeGenerator -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructEncodeGenerator import software.amazon.smithy.swift.codegen.middleware.OperationMiddleware -import software.amazon.smithy.swift.codegen.model.ShapeMetadata class TestCustomizations : DefaultHTTPProtocolCustomizations() /** @@ -38,29 +32,6 @@ class TestProtocolGenerator : HTTPBindingProtocolGenerator(TestCustomizations()) override val httpProtocolClientGeneratorFactory = HttpProtocolClientGeneratorFactory() override val shouldRenderEncodableConformance = false - override fun renderStructEncode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String? - ) { - StructEncodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer).render() - } - override fun renderStructDecode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String - ) { - StructDecodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer).render() - } - override fun addProtocolSpecificMiddleware(ctx: ProtocolGenerator.GenerationContext, operation: OperationShape) { // Intentionally empty } diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HTTPBindingProtocolGenerator.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HTTPBindingProtocolGenerator.kt index 5159f21ba..dfd5d11d9 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HTTPBindingProtocolGenerator.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HTTPBindingProtocolGenerator.kt @@ -57,6 +57,8 @@ import software.amazon.smithy.swift.codegen.integration.middlewares.SignerMiddle import software.amazon.smithy.swift.codegen.integration.middlewares.providers.HttpHeaderProvider import software.amazon.smithy.swift.codegen.integration.middlewares.providers.HttpQueryItemProvider import software.amazon.smithy.swift.codegen.integration.middlewares.providers.HttpUrlPathProvider +import software.amazon.smithy.swift.codegen.integration.serde.struct.StructDecodeGenerator +import software.amazon.smithy.swift.codegen.integration.serde.struct.StructEncodeGenerator import software.amazon.smithy.swift.codegen.integration.serde.union.UnionDecodeGenerator import software.amazon.smithy.swift.codegen.integration.serde.union.UnionEncodeGenerator import software.amazon.smithy.swift.codegen.middleware.OperationMiddlewareGenerator @@ -180,8 +182,7 @@ abstract class HTTPBindingProtocolGenerator( ) { writer.addImport(SwiftDependency.CLIENT_RUNTIME.target) writer.write("") - val path = "properties.".takeIf { shape.hasTrait() } ?: null - renderStructEncode(ctx, shape, shapeMetadata, httpBodyMembers, writer, customizations.defaultTimestampFormat, path) + renderStructEncode(ctx, shape, shapeMetadata, httpBodyMembers, writer) } } } @@ -225,27 +226,11 @@ abstract class HTTPBindingProtocolGenerator( val path = "properties.".takeIf { shape.hasTrait() } ?: "" if (shape.hasTrait()) { writer.write("") - renderStructEncode( - ctx, - shape, - mapOf(), - httpBodyMembers, - writer, - customizations.defaultTimestampFormat, - path - ) + renderStructEncode(ctx, shape, mapOf(), httpBodyMembers, writer) } if (shape.hasTrait()) { writer.write("") - renderStructDecode( - ctx, - shape, - mapOf(), - httpBodyMembers, - writer, - customizations.defaultTimestampFormat, - path - ) + renderStructDecode(ctx, shape, mapOf(), httpBodyMembers, writer) } } is UnionShape -> { @@ -439,26 +424,31 @@ abstract class HTTPBindingProtocolGenerator( override val operationMiddleware = OperationMiddlewareGenerator() protected abstract val httpProtocolClientGeneratorFactory: HttpProtocolClientGeneratorFactory + protected val httpResponseGenerator = HTTPResponseGenerator(customizations) + protected abstract val shouldRenderEncodableConformance: Boolean - protected abstract fun renderStructEncode( + + private fun renderStructEncode( ctx: ProtocolGenerator.GenerationContext, shapeContainingMembers: Shape, shapeMetadata: Map, members: List, writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String? = null, - ) - protected abstract fun renderStructDecode( + ) { + StructEncodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer).render() + } + + private fun renderStructDecode( ctx: ProtocolGenerator.GenerationContext, shapeContainingMembers: Shape, shapeMetadata: Map, members: List, writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String, - ) + ) { + StructDecodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer).render() + } + protected abstract fun addProtocolSpecificMiddleware(ctx: ProtocolGenerator.GenerationContext, operation: OperationShape) /** diff --git a/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPAWSJson11ProtocolGenerator.kt b/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPAWSJson11ProtocolGenerator.kt index 0961c1f9f..566df0680 100644 --- a/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPAWSJson11ProtocolGenerator.kt +++ b/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPAWSJson11ProtocolGenerator.kt @@ -7,12 +7,9 @@ package mocks import TestHttpProtocolClientGeneratorFactory import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait import software.amazon.smithy.model.pattern.UriPattern -import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.swift.codegen.SwiftWriter import software.amazon.smithy.swift.codegen.integration.DefaultHTTPProtocolCustomizations import software.amazon.smithy.swift.codegen.integration.HTTPBindingProtocolGenerator @@ -23,9 +20,6 @@ import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestRequ import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestResponseGenerator import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator import software.amazon.smithy.swift.codegen.integration.protocols.core.StaticHttpBindingResolver -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructDecodeGenerator -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructEncodeGenerator -import software.amazon.smithy.swift.codegen.model.ShapeMetadata class MockJsonHttpBindingResolver( private val context: ProtocolGenerator.GenerationContext, @@ -73,30 +67,6 @@ class MockHTTPAWSJson11ProtocolGenerator() : HTTPBindingProtocolGenerator(MockAW override val httpProtocolClientGeneratorFactory = TestHttpProtocolClientGeneratorFactory() override val shouldRenderEncodableConformance = false - override fun renderStructEncode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String? - ) { - val encodeGenerator = StructEncodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer) - encodeGenerator.render() - } - override fun renderStructDecode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String - ) { - StructDecodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer).render() - } - override fun addProtocolSpecificMiddleware(ctx: ProtocolGenerator.GenerationContext, operation: OperationShape) { // Intentionally empty } diff --git a/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPEC2QueryProtocolGenerator.kt b/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPEC2QueryProtocolGenerator.kt index 0129f5c53..47748e40e 100644 --- a/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPEC2QueryProtocolGenerator.kt +++ b/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPEC2QueryProtocolGenerator.kt @@ -8,13 +8,9 @@ package mocks import TestHttpProtocolClientGeneratorFactory import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait import software.amazon.smithy.model.pattern.UriPattern -import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.swift.codegen.SwiftWriter import software.amazon.smithy.swift.codegen.integration.DefaultHTTPProtocolCustomizations import software.amazon.smithy.swift.codegen.integration.HTTPBindingProtocolGenerator import software.amazon.smithy.swift.codegen.integration.HttpBindingResolver @@ -24,9 +20,6 @@ import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestRequ import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestResponseGenerator import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator import software.amazon.smithy.swift.codegen.integration.protocols.core.StaticHttpBindingResolver -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructDecodeGenerator -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructEncodeGenerator -import software.amazon.smithy.swift.codegen.model.ShapeMetadata class MockEC2QueryHTTPProtocolCustomizations() : DefaultHTTPProtocolCustomizations() @@ -50,29 +43,6 @@ class MockHTTPEC2QueryProtocolGenerator : HTTPBindingProtocolGenerator(MockEC2Qu override val protocol: ShapeId = Ec2QueryTrait.ID override val httpProtocolClientGeneratorFactory = TestHttpProtocolClientGeneratorFactory() override val shouldRenderEncodableConformance = true - override fun renderStructEncode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String? - ) { - StructEncodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer).render() - } - override fun renderStructDecode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String - ) { - val decodeGenerator = StructDecodeGenerator(ctx, shapeContainingMembers, members, mapOf(), writer) - decodeGenerator.render() - } override fun addProtocolSpecificMiddleware(ctx: ProtocolGenerator.GenerationContext, operation: OperationShape) { // Intentionally empty diff --git a/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPRestJsonProtocolGenerator.kt b/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPRestJsonProtocolGenerator.kt index 58f618c31..a22323dd6 100644 --- a/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPRestJsonProtocolGenerator.kt +++ b/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPRestJsonProtocolGenerator.kt @@ -4,12 +4,8 @@ */ import software.amazon.smithy.aws.traits.protocols.RestJson1Trait -import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.swift.codegen.SwiftWriter import software.amazon.smithy.swift.codegen.integration.DefaultHTTPProtocolCustomizations import software.amazon.smithy.swift.codegen.integration.HTTPBindingProtocolGenerator import software.amazon.smithy.swift.codegen.integration.HttpProtocolTestGenerator @@ -17,9 +13,6 @@ import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestErro import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestRequestGenerator import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestResponseGenerator import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructDecodeGenerator -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructEncodeGenerator -import software.amazon.smithy.swift.codegen.model.ShapeMetadata class MockRestJsonHTTPProtocolCustomizations() : DefaultHTTPProtocolCustomizations() class MockHTTPRestJsonProtocolGenerator : HTTPBindingProtocolGenerator(MockRestJsonHTTPProtocolCustomizations()) { @@ -28,29 +21,6 @@ class MockHTTPRestJsonProtocolGenerator : HTTPBindingProtocolGenerator(MockRestJ override val httpProtocolClientGeneratorFactory = TestHttpProtocolClientGeneratorFactory() override val shouldRenderEncodableConformance = false - override fun renderStructEncode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String? - ) { - StructEncodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer).render() - } - override fun renderStructDecode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String - ) { - StructDecodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer).render() - } - override fun addProtocolSpecificMiddleware(ctx: ProtocolGenerator.GenerationContext, operation: OperationShape) { // Intentionally empty } diff --git a/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPRestXMLProtocolGenerator.kt b/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPRestXMLProtocolGenerator.kt index eb6c0a6d2..09f70f02a 100644 --- a/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPRestXMLProtocolGenerator.kt +++ b/smithy-swift-codegen/src/test/kotlin/mocks/MockHTTPRestXMLProtocolGenerator.kt @@ -4,12 +4,8 @@ */ import software.amazon.smithy.aws.traits.protocols.RestXmlTrait -import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.swift.codegen.SwiftWriter import software.amazon.smithy.swift.codegen.integration.DefaultHTTPProtocolCustomizations import software.amazon.smithy.swift.codegen.integration.HTTPBindingProtocolGenerator import software.amazon.smithy.swift.codegen.integration.HttpProtocolTestGenerator @@ -17,9 +13,6 @@ import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestErro import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestRequestGenerator import software.amazon.smithy.swift.codegen.integration.HttpProtocolUnitTestResponseGenerator import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructDecodeGenerator -import software.amazon.smithy.swift.codegen.integration.serde.struct.StructEncodeGenerator -import software.amazon.smithy.swift.codegen.model.ShapeMetadata class MockRestXMLHTTPProtocolCustomizations() : DefaultHTTPProtocolCustomizations() @@ -29,31 +22,6 @@ class MockHTTPRestXMLProtocolGenerator : HTTPBindingProtocolGenerator(MockRestXM override val httpProtocolClientGeneratorFactory = TestHttpProtocolClientGeneratorFactory() override val shouldRenderEncodableConformance = false - override fun renderStructEncode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String? - ) { - val encoder = StructEncodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer) - encoder.render() - } - override fun renderStructDecode( - ctx: ProtocolGenerator.GenerationContext, - shapeContainingMembers: Shape, - shapeMetadata: Map, - members: List, - writer: SwiftWriter, - defaultTimestampFormat: TimestampFormatTrait.Format, - path: String - ) { - val decodeGenerator = StructDecodeGenerator(ctx, shapeContainingMembers, members, shapeMetadata, writer) - decodeGenerator.render() - } - override fun addProtocolSpecificMiddleware(ctx: ProtocolGenerator.GenerationContext, operation: OperationShape) { // Intentionally empty }