diff --git a/axum_serde_valid/Cargo.toml b/axum_serde_valid/Cargo.toml index ea5d2d4..f3bdaf2 100644 --- a/axum_serde_valid/Cargo.toml +++ b/axum_serde_valid/Cargo.toml @@ -11,10 +11,10 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -aide = { version = "^0.10", optional = true, features = ["axum"] } +aide = { version = "^0.13", optional = true, features = ["axum"] } async-trait = "^0.1" -axum = "^0.6" -http-body = "^0.4" +axum = "^0.7" +http-body = "^1.0" jsonschema = { version = "^0.17", optional = true } schemars = { version = "^0.8", optional = true } serde = { workspace = true } @@ -23,10 +23,10 @@ serde_valid = { version = "0.16.1", path = "../serde_valid", features = [ "flatten", ] } tracing = "^0.1" -serde_urlencoded="0.7.1" +serde_urlencoded = "0.7.1" [dev-dependencies] -hyper = "0.14.23" +hyper = "^1.0" mime = "0.3" tokio = { version = "1.24", features = ["full"] } tower = { version = "0.4", features = ["util"] } diff --git a/axum_serde_valid/src/json.rs b/axum_serde_valid/src/json.rs index b30a3f7..e8a23ce 100644 --- a/axum_serde_valid/src/json.rs +++ b/axum_serde_valid/src/json.rs @@ -13,12 +13,11 @@ //! //! - aide: support for [aide](https://docs.rs/aide/latest/aide/) -use std::ops::Deref; - use async_trait::async_trait; -use axum::http::Request; -use axum::{extract::FromRequest, response::IntoResponse, BoxError}; +use axum::extract::Request; +use axum::{extract::FromRequest, response::IntoResponse}; use serde::Serialize; +use std::ops::Deref; /// Wrapper type over [`axum::Json`] that validates /// requests and responds with a more helpful validation @@ -40,18 +39,15 @@ impl From for Json { } #[async_trait] -impl FromRequest for Json +impl FromRequest for Json where T: crate::validated::Deserialize + 'static, - B: http_body::Body + Send + 'static, - B::Data: Send, - B::Error: Into, S: Send + Sync, { type Rejection = crate::rejection::Rejection; - async fn from_request(req: Request, state: &S) -> Result { - crate::request::from_request::<_, _, T>(req, state) + async fn from_request(req: Request, state: &S) -> Result { + crate::request::from_request::<_, T>(req, state) .await .map(Json) } @@ -145,7 +141,7 @@ mod test { assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY); assert_eq!( serde_json::from_slice::( - &hyper::body::to_bytes(response.into_body()).await?[..], + &axum::body::to_bytes(response.into_body(), 1_000_000).await?, )?, json!({"errors": [ { @@ -185,7 +181,7 @@ mod test { assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY); assert_eq!( serde_json::from_slice::( - &hyper::body::to_bytes(response.into_body()).await?[..], + &axum::body::to_bytes(response.into_body(), 1_000_000).await? )?, json!({"errors": [ { @@ -225,7 +221,7 @@ mod test { assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY); assert_eq!( serde_json::from_slice::( - &hyper::body::to_bytes(response.into_body()).await?[..], + &axum::body::to_bytes(response.into_body(), 1_000_000).await?, )?, json!({"errors": [ { diff --git a/axum_serde_valid/src/request.rs b/axum_serde_valid/src/request.rs index 739829b..81d2ad8 100644 --- a/axum_serde_valid/src/request.rs +++ b/axum_serde_valid/src/request.rs @@ -1,16 +1,13 @@ use std::any::type_name; -use axum::{extract::FromRequest, BoxError}; +use axum::extract::FromRequest; use serde_json::Value; -pub async fn from_request( - req: axum::http::Request, +pub async fn from_request( + req: axum::extract::Request, state: &S, ) -> Result where - B: http_body::Body + Send + 'static, - B::Data: Send, - B::Error: Into, S: Send + Sync, T: crate::validated::Deserialize + 'static, {