Unverified Commit 43e3e298 authored by 82marbag's avatar 82marbag Committed by GitHub
Browse files

Expand protocol layouts (#1753)



Split runtime protocols layout

Signed-off-by: default avatarDaniele Ahmed <ahmeddan@amazon.de>
parent ff13b087
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -135,8 +135,8 @@ class PythonApplicationGenerator(
        ) {
            rustBlockTemplate(
                """
                /// Dynamically codegenerate the routes, allowing to build the Smithy [#{SmithyServer}::Router].
                pub fn build_router(&mut self, event_loop: &#{pyo3}::PyAny) -> #{pyo3}::PyResult<#{SmithyServer}::Router>
                /// Dynamically codegenerate the routes, allowing to build the Smithy [#{SmithyServer}::routing::Router].
                pub fn build_router(&mut self, event_loop: &#{pyo3}::PyAny) -> #{pyo3}::PyResult<#{SmithyServer}::routing::Router>
                """,
                *codegenScope,
            ) {
@@ -162,7 +162,7 @@ class PythonApplicationGenerator(
                }
                rustTemplate(
                    """
                    let router: #{SmithyServer}::Router = router
                    let router: #{SmithyServer}::routing::Router = router
                        .build()
                        .expect("Unable to build operation registry")
                        .into();
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ class PythonServerServiceGenerator(
    private val rustCrate: RustCrate,
    protocolGenerator: ProtocolGenerator,
    protocolSupport: ProtocolSupport,
    protocol: ServerProtocol,
    private val protocol: ServerProtocol,
    private val context: CoreCodegenContext,
) : ServerServiceGenerator(rustCrate, protocolGenerator, protocolSupport, protocol, context) {

+3 −3
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ object ServerRuntimeType {
    fun ResponseRejection(runtimeConfig: RuntimeConfig) =
        RuntimeType("ResponseRejection", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::rejection")

    fun Protocol(name: String, runtimeConfig: RuntimeConfig) =
        RuntimeType(name, ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::protocols")
    fun Protocol(name: String, path: String, runtimeConfig: RuntimeConfig) =
        RuntimeType(name, ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::" + path)

    fun Protocol(runtimeConfig: RuntimeConfig) = Protocol("Protocol", runtimeConfig)
    fun Protocol(runtimeConfig: RuntimeConfig) = Protocol("Protocol", "", runtimeConfig)
}
+3 −3
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ class ServerServiceGeneratorV2(
                {
                    let router = #{Router:W};
                    $serviceName {
                        router: #{SmithyHttpServer}::routing::routers::RoutingService::new(router),
                        router: #{SmithyHttpServer}::routers::RoutingService::new(router),
                    }
                }
            }
@@ -280,7 +280,7 @@ class ServerServiceGeneratorV2(
            """
            ##[derive(Clone)]
            pub struct $serviceName<S> {
                router: #{SmithyHttpServer}::routing::routers::RoutingService<#{Router}<S>, #{Protocol}>,
                router: #{SmithyHttpServer}::routers::RoutingService<#{Router}<S>, #{Protocol}>,
            }

            impl $serviceName<()> {
@@ -331,7 +331,7 @@ class ServerServiceGeneratorV2(
            {
                type Response = #{Http}::Response<#{SmithyHttpServer}::body::BoxBody>;
                type Error = S::Error;
                type Future = #{SmithyHttpServer}::routing::routers::RoutingFuture<S, B>;
                type Future = #{SmithyHttpServer}::routers::RoutingFuture<S, B>;

                fn poll_ready(&mut self, cx: &mut std::task::Context) -> std::task::Poll<Result<(), Self::Error>> {
                    self.router.poll_ready(cx)
+9 −10
Original line number Diff line number Diff line
@@ -97,18 +97,17 @@ class ServerAwsJsonProtocol(
    }

    override fun markerStruct(): RuntimeType {
        val name = when (version) {
        return when (version) {
            is AwsJsonVersion.Json10 -> {
                "AwsJson10"
                ServerRuntimeType.Protocol("AwsJson10", "aws_json_10", runtimeConfig)
            }
            is AwsJsonVersion.Json11 -> {
                "AwsJson11"
                ServerRuntimeType.Protocol("AwsJson11", "aws_json_11", runtimeConfig)
            }
        }
        return ServerRuntimeType.Protocol(name, runtimeConfig)
    }

    override fun routerType() = RuntimeType("AwsJsonRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing::routers::aws_json")
    override fun routerType() = RuntimeType("AwsJsonRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::aws_json::router")

    override fun routerConstruction(operationValues: Iterable<Writable>): Writable = writable {
        val allOperationShapes = allOperations(coreCodegenContext)
@@ -159,7 +158,7 @@ class ServerAwsJsonProtocol(
    }
}

private fun restRouterType(runtimeConfig: RuntimeConfig) = RuntimeType("RestRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing::routers::rest")
private fun restRouterType(runtimeConfig: RuntimeConfig) = RuntimeType("RestRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::rest::router")

private fun restRouterConstruction(
    protocol: ServerProtocol,
@@ -212,7 +211,7 @@ class ServerRestJsonProtocol(
        fun fromCoreProtocol(restJson: RestJson): ServerRestJsonProtocol = ServerRestJsonProtocol(restJson.coreCodegenContext)
    }

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

    override fun routerType() = restRouterType(runtimeConfig)

@@ -241,7 +240,7 @@ class ServerRestXmlProtocol(
        }
    }

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

    override fun routerType() = restRouterType(runtimeConfig)

Loading