Skip to content

Commit

Permalink
Merge pull request #21 from yassun7010/update_axum_version
Browse files Browse the repository at this point in the history
feat: update axum version.
  • Loading branch information
yassun7010 authored Jan 6, 2024
2 parents 9418102 + f663fdc commit 1aea7b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
10 changes: 5 additions & 5 deletions axum_serde_valid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }
Expand Down
22 changes: 9 additions & 13 deletions axum_serde_valid/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,18 +39,15 @@ impl<T> From<T> for Json<T> {
}

#[async_trait]
impl<T, S, B> FromRequest<S, B> for Json<T>
impl<T, S> FromRequest<S> for Json<T>
where
T: crate::validated::Deserialize + 'static,
B: http_body::Body + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
S: Send + Sync,
{
type Rejection = crate::rejection::Rejection;

async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
crate::request::from_request::<_, _, T>(req, state)
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
crate::request::from_request::<_, T>(req, state)
.await
.map(Json)
}
Expand Down Expand Up @@ -145,7 +141,7 @@ mod test {
assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY);
assert_eq!(
serde_json::from_slice::<serde_json::Value>(
&hyper::body::to_bytes(response.into_body()).await?[..],
&axum::body::to_bytes(response.into_body(), 1_000_000).await?,
)?,
json!({"errors": [
{
Expand Down Expand Up @@ -185,7 +181,7 @@ mod test {
assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY);
assert_eq!(
serde_json::from_slice::<serde_json::Value>(
&hyper::body::to_bytes(response.into_body()).await?[..],
&axum::body::to_bytes(response.into_body(), 1_000_000).await?
)?,
json!({"errors": [
{
Expand Down Expand Up @@ -225,7 +221,7 @@ mod test {
assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY);
assert_eq!(
serde_json::from_slice::<serde_json::Value>(
&hyper::body::to_bytes(response.into_body()).await?[..],
&axum::body::to_bytes(response.into_body(), 1_000_000).await?,
)?,
json!({"errors": [
{
Expand Down
9 changes: 3 additions & 6 deletions axum_serde_valid/src/request.rs
Original file line number Diff line number Diff line change
@@ -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<S, B, T>(
req: axum::http::Request<B>,
pub async fn from_request<S, T>(
req: axum::extract::Request,
state: &S,
) -> Result<T, crate::rejection::Rejection>
where
B: http_body::Body + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
S: Send + Sync,
T: crate::validated::Deserialize + 'static,
{
Expand Down

0 comments on commit 1aea7b9

Please sign in to comment.