Unverified Commit 003b1db6 authored by 82marbag's avatar 82marbag Committed by GitHub
Browse files

Remove axum-core dependency (#1368)



This change removes the dependency on axum-core and brings in the
relevant resources we are using from that crate.

Issue: #1170

Signed-off-by: default avatarDaniele Ahmed <ahmeddan@amazon.de>
parent 34369e2d
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig
 */
object ServerCargoDependency {
    val AsyncTrait: CargoDependency = CargoDependency("async-trait", CratesIo("0.1"))
    val AxumCore: CargoDependency = CargoDependency("axum-core", CratesIo("0.1"))
    val FuturesUtil: CargoDependency = CargoDependency("futures-util", CratesIo("0.3"))
    val Nom: CargoDependency = CargoDependency("nom", CratesIo("7"))
    val PinProjectLite: CargoDependency = CargoDependency("pin-project-lite", CratesIo("0.2"))
+3 −4
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ class ServerOperationHandlerGenerator(
    private val runtimeConfig = codegenContext.runtimeConfig
    private val codegenScope = arrayOf(
        "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(),
        "AxumCore" to ServerCargoDependency.AxumCore.asType(),
        "PinProjectLite" to ServerCargoDependency.PinProjectLite.asType(),
        "Tower" to ServerCargoDependency.Tower.asType(),
        "FuturesUtil" to ServerCargoDependency.FuturesUtil.asType(),
@@ -106,9 +105,9 @@ class ServerOperationHandlerGenerator(
                    """
                    type Sealed = #{ServerOperationHandler}::sealed::Hidden;
                    async fn call(self, req: #{http}::Request<B>) -> #{http}::Response<#{SmithyHttpServer}::body::BoxBody> {
                        let mut req = #{AxumCore}::extract::RequestParts::new(req);
                        use #{AxumCore}::extract::FromRequest;
                        use #{AxumCore}::response::IntoResponse;
                        let mut req = #{SmithyHttpServer}::request::RequestParts::new(req);
                        use #{SmithyHttpServer}::request::FromRequest;
                        use #{SmithyHttpServer}::response::IntoResponse;
                        let input_wrapper = match $inputWrapperName::from_request(&mut req).await {
                            Ok(v) => v,
                            Err(runtime_error) => {
+6 −7
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ class ServerProtocolTestGenerator(
        "SmithyHttp" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType(),
        "Http" to CargoDependency.Http.asType(),
        "Hyper" to CargoDependency.Hyper.asType(),
        "AxumCore" to ServerCargoDependency.AxumCore.asType(),
        "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType(),
        "AssertEq" to CargoDependency.PrettyAssertions.asType().member("assert_eq!")
    )
@@ -294,7 +293,7 @@ class ServerProtocolTestGenerator(
        rustTemplate(
            """
            let output = super::$operationImpl;
            use #{AxumCore}::response::IntoResponse;
            use #{SmithyHttpServer}::response::IntoResponse;
            let http_response = output.into_response();
            """,
            *codegenScope,
@@ -316,10 +315,10 @@ class ServerProtocolTestGenerator(
        val operationName = "${operationSymbol.name}${ServerHttpBoundProtocolGenerator.OPERATION_INPUT_WRAPPER_SUFFIX}"
        rustTemplate(
            """
            use #{AxumCore}::extract::FromRequest;
            let mut http_request = #{AxumCore}::extract::RequestParts::new(http_request);
            use #{SmithyHttpServer}::request::FromRequest;
            let mut http_request = #{SmithyHttpServer}::request::RequestParts::new(http_request);
            let rejection = super::$operationName::from_request(&mut http_request).await.expect_err("request was accepted but we expected it to be rejected");
            use #{AxumCore}::response::IntoResponse;
            use #{SmithyHttpServer}::response::IntoResponse;
            let http_response = rejection.into_response();
            """,
            *codegenScope,
@@ -381,8 +380,8 @@ class ServerProtocolTestGenerator(
        val operationName = "${operationSymbol.name}${ServerHttpBoundProtocolGenerator.OPERATION_INPUT_WRAPPER_SUFFIX}"
        rustWriter.rustTemplate(
            """
            use #{AxumCore}::extract::FromRequest;
            let mut http_request = #{AxumCore}::extract::RequestParts::new(http_request);
            use #{SmithyHttpServer}::request::FromRequest;
            let mut http_request = #{SmithyHttpServer}::request::RequestParts::new(http_request);
            let parsed = super::$operationName::from_request(&mut http_request).await.expect("failed to parse request").0;
            """,
            *codegenScope,
+12 −13
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ private class ServerHttpBoundProtocolTraitImplGenerator(

    private val codegenScope = arrayOf(
        "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(),
        "AxumCore" to ServerCargoDependency.AxumCore.asType(),
        "Cow" to ServerRuntimeType.Cow,
        "DateTime" to RuntimeType.DateTime(runtimeConfig),
        "HttpBody" to CargoDependency.HttpBody.asType(),
@@ -155,20 +154,20 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
        val operationName = symbolProvider.toSymbol(operationShape).name
        val inputName = "${operationName}${ServerHttpBoundProtocolGenerator.OPERATION_INPUT_WRAPPER_SUFFIX}"

        // Implement Axum `FromRequest` trait for input types.
        // Implement `FromRequest` trait for input types.
        rustTemplate(
            """
            ##[derive(Debug)]
            pub(crate) struct $inputName(#{I});
            ##[#{AsyncTrait}::async_trait]
            impl<B> #{AxumCore}::extract::FromRequest<B> for $inputName
            impl<B> #{SmithyHttpServer}::request::FromRequest<B> for $inputName
            where
                B: #{SmithyHttpServer}::body::HttpBody + Send, ${streamingBodyTraitBounds(operationShape)}
                B::Data: Send,
                #{RequestRejection} : From<<B as #{SmithyHttpServer}::body::HttpBody>::Error>
            {
                type Rejection = #{RuntimeError};
                async fn from_request(req: &mut #{AxumCore}::extract::RequestParts<B>) -> Result<Self, Self::Rejection> {
                async fn from_request(req: &mut #{SmithyHttpServer}::request::RequestParts<B>) -> Result<Self, Self::Rejection> {
                    #{parse_request}(req)
                        .await
                        .map($inputName)
@@ -186,7 +185,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
            "parse_request" to serverParseRequest(operationShape)
        )

        // Implement Axum `IntoResponse` for output types.
        // Implement `IntoResponse` for output types.

        val outputName = "${operationName}${ServerHttpBoundProtocolGenerator.OPERATION_OUTPUT_WRAPPER_SUFFIX}"
        val errorSymbol = operationShape.errorSymbol(symbolProvider)
@@ -211,7 +210,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
                    Self::Error(err) => {
                        match #{serialize_error}(&err) {
                            Ok(mut response) => {
                                response.extensions_mut().insert(aws_smithy_http_server::extension::ModeledErrorExtension::new(err.name()));
                                response.extensions_mut().insert(#{SmithyHttpServer}::extension::ModeledErrorExtension::new(err.name()));
                                response
                            },
                            Err(e) => {
@@ -232,8 +231,8 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
                    Error(#{E})
                }
                ##[#{AsyncTrait}::async_trait]
                impl #{AxumCore}::response::IntoResponse for $outputName {
                    fn into_response(self) -> #{AxumCore}::response::Response {
                impl #{SmithyHttpServer}::response::IntoResponse for $outputName {
                    fn into_response(self) -> #{SmithyHttpServer}::response::Response {
                        $intoResponseImpl
                    }
                }
@@ -264,8 +263,8 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
                """
                pub(crate) struct $outputName(#{O});
                ##[#{AsyncTrait}::async_trait]
                impl #{AxumCore}::response::IntoResponse for $outputName {
                    fn into_response(self) -> #{AxumCore}::response::Response {
                impl #{SmithyHttpServer}::response::IntoResponse for $outputName {
                    fn into_response(self) -> #{SmithyHttpServer}::response::Response {
                        $intoResponseImpl
                    }
                }
@@ -329,7 +328,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
            it.rustBlockTemplate(
                """
                pub async fn $fnName<B>(
                    ##[allow(unused_variables)] request: &mut #{AxumCore}::extract::RequestParts<B>
                    ##[allow(unused_variables)] request: &mut #{SmithyHttpServer}::request::RequestParts<B>
                ) -> std::result::Result<
                    #{I},
                    #{RequestRejection}
@@ -369,7 +368,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
                pub fn $fnName(
                    ##[allow(unused_variables)] output: #{O}
                ) -> std::result::Result<
                    #{AxumCore}::response::Response,
                    #{SmithyHttpServer}::response::Response,
                    #{ResponseRejection}
                >
                """.trimIndent(),
@@ -392,7 +391,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
        return RuntimeType.forInlineFun(fnName, operationSerModule) {
            Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it)
            it.rustBlockTemplate(
                "pub fn $fnName(error: &#{E}) -> std::result::Result<#{AxumCore}::response::Response, #{ResponseRejection}>",
                "pub fn $fnName(error: &#{E}) -> std::result::Result<#{SmithyHttpServer}::response::Response, #{ResponseRejection}>",
                *codegenScope,
                "E" to errorSymbol
            ) {
+0 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ aws-smithy-types = { path = "../aws-smithy-types" }
aws-smithy-json = { path = "../aws-smithy-json" }
aws-smithy-xml = { path = "../aws-smithy-xml" }
async-trait = "0.1"
axum-core = "0.1.2"
bytes = "1.1"
futures-util = { version = "0.3", default-features = false }
http = "0.2"
Loading