Unverified Commit 1f405f63 authored by Harry Barber's avatar Harry Barber Committed by GitHub
Browse files

Remove `fromCoreProtocol` in favour of `as` downcasting (#2000)

parent 06c23f65
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ class PythonServerCodegenVisitor(
            rustCrate,
            protocolGenerator,
            protocolGeneratorFactory.support(),
            ServerProtocol.fromCoreProtocol(protocolGeneratorFactory.protocol(codegenContext)),
            protocolGeneratorFactory.protocol(codegenContext) as ServerProtocol,
            codegenContext,
        )
            .render()
+1 −1
Original line number Diff line number Diff line
@@ -438,7 +438,7 @@ open class ServerCodegenVisitor(
            rustCrate,
            protocolGenerator,
            protocolGeneratorFactory.support(),
            ServerProtocol.fromCoreProtocol(protocolGeneratorFactory.protocol(codegenContext)),
            protocolGeneratorFactory.protocol(codegenContext) as ServerProtocol,
            codegenContext,
        )
            .render()
+0 −25
Original line number Diff line number Diff line
@@ -78,16 +78,6 @@ interface ServerProtocol : Protocol {
     * Returns a boolean indicating whether to perform this check.
     */
    fun serverContentTypeCheckNoModeledInput(): Boolean = false

    companion object {
        /** Upgrades the core protocol to a `ServerProtocol`. */
        fun fromCoreProtocol(protocol: Protocol): ServerProtocol = when (protocol) {
            is AwsJson -> ServerAwsJsonProtocol.fromCoreProtocol(protocol)
            is RestJson -> ServerRestJsonProtocol.fromCoreProtocol(protocol)
            is RestXml -> ServerRestXmlProtocol.fromCoreProtocol(protocol)
            else -> throw IllegalStateException("unsupported protocol")
        }
    }
}

class ServerAwsJsonProtocol(
@@ -120,11 +110,6 @@ class ServerAwsJsonProtocol(
    override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator =
        ServerAwsJsonSerializerGenerator(serverCodegenContext, httpBindingResolver, awsJsonVersion)

    companion object {
        fun fromCoreProtocol(awsJson: AwsJson): ServerAwsJsonProtocol =
            ServerAwsJsonProtocol(awsJson.codegenContext as ServerCodegenContext, awsJson.version)
    }

    override fun markerStruct(): RuntimeType {
        return when (version) {
            is AwsJsonVersion.Json10 -> {
@@ -194,10 +179,6 @@ class ServerRestJsonProtocol(
    override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator =
        ServerRestJsonSerializerGenerator(serverCodegenContext, httpBindingResolver)

    companion object {
        fun fromCoreProtocol(restJson: RestJson): ServerRestJsonProtocol = ServerRestJsonProtocol(restJson.codegenContext as ServerCodegenContext)
    }

    override fun markerStruct() = ServerRuntimeType.Protocol("RestJson1", "rest_json_1", runtimeConfig)

    override fun routerType() = restRouterType(runtimeConfig)
@@ -222,12 +203,6 @@ class ServerRestXmlProtocol(
) : RestXml(codegenContext), ServerProtocol {
    val runtimeConfig = codegenContext.runtimeConfig

    companion object {
        fun fromCoreProtocol(restXml: RestXml): ServerRestXmlProtocol {
            return ServerRestXmlProtocol(restXml.codegenContext)
        }
    }

    override fun markerStruct() = ServerRuntimeType.Protocol("RestXml", "rest_xml", runtimeConfig)

    override fun routerType() = restRouterType(runtimeConfig)
+3 −4
Original line number Diff line number Diff line
@@ -125,7 +125,6 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
    private val operationDeserModule = RustModule.private("operation_deser")
    private val operationSerModule = RustModule.private("operation_ser")
    private val typeConversionGenerator = TypeConversionGenerator(model, symbolProvider, runtimeConfig)
    private val serverProtocol = ServerProtocol.fromCoreProtocol(protocol)

    private val codegenScope = arrayOf(
        "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(),
@@ -252,7 +251,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
            """.trimIndent(),
            *codegenScope,
            "I" to inputSymbol,
            "Marker" to serverProtocol.markerStruct(),
            "Marker" to protocol.markerStruct(),
            "parse_request" to serverParseRequest(operationShape),
            "verifyAcceptHeader" to verifyAcceptHeader,
            "verifyRequestContentTypeHeader" to verifyRequestContentTypeHeader,
@@ -315,7 +314,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
                *codegenScope,
                "O" to outputSymbol,
                "E" to errorSymbol,
                "Marker" to serverProtocol.markerStruct(),
                "Marker" to protocol.markerStruct(),
                "serialize_response" to serverSerializeResponse(operationShape),
                "serialize_error" to serverSerializeError(operationShape),
            )
@@ -348,7 +347,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
                """.trimIndent(),
                *codegenScope,
                "O" to outputSymbol,
                "Marker" to serverProtocol.markerStruct(),
                "Marker" to protocol.markerStruct(),
                "serialize_response" to serverSerializeResponse(operationShape),
            )
        }
+1 −2
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols
import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport
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.RestXml
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerRestXmlProtocol

@@ -17,7 +16,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser
 * with RestXml specific configurations.
 */
class ServerRestXmlFactory : ProtocolGeneratorFactory<ServerHttpBoundProtocolGenerator, ServerCodegenContext> {
    override fun protocol(codegenContext: ServerCodegenContext): Protocol = RestXml(codegenContext)
    override fun protocol(codegenContext: ServerCodegenContext): Protocol = ServerRestXmlProtocol(codegenContext)

    override fun buildProtocolGenerator(codegenContext: ServerCodegenContext): ServerHttpBoundProtocolGenerator =
        ServerHttpBoundProtocolGenerator(codegenContext, ServerRestXmlProtocol(codegenContext))
Loading