From b05787c76b45418c78b3ab9fc587f978d19287ad Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 28 Mar 2023 09:48:02 -0700 Subject: [PATCH] Remove `ProtocolTraitImplGenerator` from `codegen-core` (#2504) --- .../protocol/ClientProtocolGenerator.kt | 6 +++--- .../protocols/HttpBoundProtocolGenerator.kt | 7 +++---- .../protocol/ProtocolTestGeneratorTest.kt | 6 +++--- .../generators/protocol/ProtocolGenerator.kt | 21 ------------------- .../protocol/ServerProtocolGenerator.kt | 6 +++--- .../ServerHttpBoundProtocolGenerator.kt | 7 +++---- 6 files changed, 15 insertions(+), 38 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt index 8cd5fd933..0f5328961 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt @@ -10,6 +10,7 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.client.fluentBuilderType +import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBoundProtocolTraitImplGenerator import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.derive import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter @@ -23,7 +24,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSectio import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.util.inputShape @@ -35,8 +35,8 @@ open class ClientProtocolGenerator( * This is the serializer side of request dispatch */ private val makeOperationGenerator: MakeOperationGenerator, - private val traitGenerator: ProtocolTraitImplGenerator, -) : ProtocolGenerator(codegenContext, protocol, traitGenerator) { + private val traitGenerator: HttpBoundProtocolTraitImplGenerator, +) : ProtocolGenerator(codegenContext, protocol) { /** * Render all code required for serializing requests and deserializing responses for the operation * diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt index 18a2f0b32..76fe6eefa 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt @@ -29,7 +29,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustom import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBoundProtocolPayloadGenerator @@ -62,10 +61,10 @@ class HttpBoundProtocolGenerator( HttpBoundProtocolTraitImplGenerator(codegenContext, protocol), ) -class HttpBoundProtocolTraitImplGenerator( +open class HttpBoundProtocolTraitImplGenerator( private val codegenContext: ClientCodegenContext, private val protocol: Protocol, -) : ProtocolTraitImplGenerator { +) { private val symbolProvider = codegenContext.symbolProvider private val model = codegenContext.model private val runtimeConfig = codegenContext.runtimeConfig @@ -100,7 +99,7 @@ class HttpBoundProtocolTraitImplGenerator( ) } - override fun generateTraitImpls( + open fun generateTraitImpls( operationWriter: RustWriter, operationShape: OperationShape, customizations: List, diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt index 5413cc767..060e636c3 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt @@ -13,6 +13,7 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBoundProtocolTraitImplGenerator import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.escape @@ -23,7 +24,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolPayloadGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap @@ -44,9 +44,9 @@ private class TestProtocolPayloadGenerator(private val body: String) : ProtocolP } private class TestProtocolTraitImplGenerator( - private val codegenContext: CodegenContext, + private val codegenContext: ClientCodegenContext, private val correctResponse: String, -) : ProtocolTraitImplGenerator { +) : HttpBoundProtocolTraitImplGenerator(codegenContext, RestJson(codegenContext)) { private val symbolProvider = codegenContext.symbolProvider override fun generateTraitImpls( diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolGenerator.kt index 660dd2555..4f410bf03 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolGenerator.kt @@ -8,7 +8,6 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators.protocol import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol /** @@ -46,21 +45,6 @@ interface ProtocolPayloadGenerator { fun generatePayload(writer: RustWriter, self: String, operationShape: OperationShape) } -/** - * Protocol Trait implementation generator - * - * **Note:** There is only one real implementation of this interface. The other implementation is test-only. - * All protocols use the same class. - * - * Protocols implement one of two traits to enable parsing HTTP responses: - * 1. `ParseHttpResponse`: Streaming binary operations - * 2. `ParseStrictResponse`: Non-streaming operations for the body must be "strict" (as in, not lazy) where the parser - * must have the complete body to return a result. - */ -interface ProtocolTraitImplGenerator { - fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) -} - /** * Class providing scaffolding for HTTP based protocols that must build an HTTP request (headers / URL) and a body. */ @@ -72,11 +56,6 @@ abstract class ProtocolGenerator( * and an output shape is build from an `http::Response`. */ private val protocol: Protocol, - /** - * Operations generate implementations of ParseHttpResponse or ParseStrictResponse. - * This is the deserializer side of request dispatch (parsing the response) - */ - private val traitGenerator: ProtocolTraitImplGenerator, ) { protected val symbolProvider = codegenContext.symbolProvider protected val model = codegenContext.model diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt index b142f8956..360588929 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt @@ -9,13 +9,13 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator +import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpBoundProtocolTraitImplGenerator open class ServerProtocolGenerator( codegenContext: CodegenContext, val protocol: ServerProtocol, - private val traitGenerator: ProtocolTraitImplGenerator, -) : ProtocolGenerator(codegenContext, protocol, traitGenerator) { + private val traitGenerator: ServerHttpBoundProtocolTraitImplGenerator, +) : ProtocolGenerator(codegenContext, protocol) { /** * The server implementation uses this method to generate implementations of the `from_request` and `into_response` * traits for operation input and output shapes, respectively. diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index 16441ac0c..79340964a 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -45,7 +45,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.TypeConversionGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.http.HttpMessageType -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName import software.amazon.smithy.rust.codegen.core.smithy.isOptional import software.amazon.smithy.rust.codegen.core.smithy.mapRustType @@ -103,10 +102,10 @@ class ServerHttpBoundProtocolGenerator( * Generate all operation input parsers and output serializers for streaming and * non-streaming types. */ -private class ServerHttpBoundProtocolTraitImplGenerator( +class ServerHttpBoundProtocolTraitImplGenerator( private val codegenContext: ServerCodegenContext, private val protocol: ServerProtocol, -) : ProtocolTraitImplGenerator { +) { private val logger = Logger.getLogger(javaClass.name) private val symbolProvider = codegenContext.symbolProvider private val unconstrainedShapeSymbolProvider = codegenContext.unconstrainedShapeSymbolProvider @@ -139,7 +138,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( "http" to RuntimeType.Http, ) - override fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) { + fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) { val inputSymbol = symbolProvider.toSymbol(operationShape.inputShape(model)) val outputSymbol = symbolProvider.toSymbol(operationShape.outputShape(model)) -- GitLab