Skip to content

Commit

Permalink
deps: bump axum to 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gengteng committed Jan 25, 2025
1 parent 73e5ef0 commit cdec7d9
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 70 deletions.
32 changes: 16 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "axum-valid"
version = "0.21.0"
version = "0.22.0"
description = "Provides validation extractors for your Axum application, allowing you to validate data using validator, garde, validify or all of them."
authors = ["GengTeng <[email protected]>"]
license = "MIT"
Expand All @@ -26,8 +26,8 @@ features = ["full", "aide"]

[dependencies]
axum = { version = "0.8", default-features = false }
garde = { version = "0.21.0", optional = true }
validator = { version = "0.19.0", optional = true }
garde = { version = "0.22.0", optional = true }
validator = { version = "0.20.0", optional = true }
validify = { version = "1.4.0", optional = true }

[dependencies.axum-extra]
Expand All @@ -36,38 +36,38 @@ default-features = false
optional = true

[dependencies.axum-serde]
version = "0.7.0"
version = "0.8.1"
optional = true

[dependencies.axum_typed_multipart]
version = "0.14"
version = "0.15.1"
optional = true

[dependencies.serde]
version = "1.0.210"
version = "1.0.217"
optional = true

[dependencies.aide]
version = "0.13.4"
version = "0.14.0"
optional = true

[dev-dependencies]
anyhow = "1.0.87"
axum = { version = "0.8", features = ["macros"] }
tokio = { version = "1.34.0", features = ["full"] }
tokio = { version = "1.43.0", features = ["full"] }
reqwest = { version = "0.12.3", features = ["json", "multipart"] }
serde = { version = "1.0.195", features = ["derive"] }
validator = { version = "0.19.0", features = ["derive"] }
garde = { version = "0.21.0", features = ["serde", "derive"] }
validator = { version = "0.20.0", features = ["derive"] }
garde = { version = "0.22.0", features = ["serde", "derive"] }
serde_json = "1.0.108"
serde_yaml = "0.9.27"
quick-xml = { version = "0.36.1", features = ["serialize"] }
serde_yaml = "0.9.33"
quick-xml = { version = "0.37.1", features = ["serialize"] }
ciborium = { version = "0.2.2" }
toml = "0.8.8"
toml = "0.8.14"
mime = "0.3.17"
prost = "0.12.3"
once_cell = "1.18.0"
rmp-serde = "1.1.2"
prost = "0.13.4"
once_cell = "1.20.2"
rmp-serde = "1.3.0"

[features]
default = ["basic", "validator"]
Expand Down
11 changes: 5 additions & 6 deletions src/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
//! }
//! }
//!
//! #[axum::async_trait]
//! impl<S> FromRequestParts<S> for Parameter
//! where
//! S: Send + Sync,
Expand Down Expand Up @@ -108,7 +107,7 @@
//! }
//! }
//!
//! #[axum::async_trait]
//!
//! impl<S> FromRequestParts<S> for Parameter
//! where
//! S: Send + Sync,
Expand Down Expand Up @@ -189,7 +188,7 @@
//! }
//! }
//!
//! #[axum::async_trait]
//!
//! impl<S> FromRequestParts<S> for Parameter
//! where
//! S: Send + Sync,
Expand Down Expand Up @@ -242,7 +241,7 @@
//! }
//! }
//!
//! #[axum::async_trait]
//!
//! impl<S> FromRequestParts<S> for Parameter
//! where
//! S: Send + Sync,
Expand Down Expand Up @@ -332,7 +331,7 @@
//! }
//! }
//!
//! #[axum::async_trait]
//!
//! impl<S> FromRequestParts<S> for Parameter
//! where
//! S: Send + Sync,
Expand Down Expand Up @@ -407,7 +406,7 @@
//! }
//! }
//!
//! #[axum::async_trait]
//!
//! impl<S> FromRequestParts<S> for Parameter
//! where
//! S: Send + Sync,
Expand Down
2 changes: 1 addition & 1 deletion src/extra/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mod tests {
use serde::Serialize;

impl<T: ValidTestParameter + Serialize> ValidTest for Form<T> {
const ERROR_STATUS_CODE: StatusCode = StatusCode::BAD_REQUEST;
const ERROR_STATUS_CODE: StatusCode = StatusCode::UNPROCESSABLE_ENTITY;

fn set_valid_request(builder: RequestBuilder) -> RequestBuilder {
builder.form(T::valid())
Expand Down
4 changes: 2 additions & 2 deletions src/extra/typed_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//! }
//!
//! #[derive(TypedPath, Deserialize, Validate)]
//! #[typed_path("/extra_typed_path/:v0/:v1")]
//! #[typed_path("/extra_typed_path/{v0}/{v1}")]
//! struct Parameter {
//! #[validate(range(min = 5, max = 10))]
//! v0: i32,
Expand Down Expand Up @@ -63,7 +63,7 @@
//! }
//!
//! #[derive(TypedPath, Deserialize, Validate)]
//! #[typed_path("/extra_typed_path/:v0/:v1")]
//! #[typed_path("/extra_typed_path/{v0}/{v1}")]
//! struct Parameter {
//! #[garde(range(min = 5, max = 10))]
//! v0: i32,
Expand Down
5 changes: 4 additions & 1 deletion src/garde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ impl<T> aide::OperationInput for Garde<T>
where
T: aide::OperationInput,
{
fn operation_input(ctx: &mut aide::gen::GenContext, operation: &mut aide::openapi::Operation) {
fn operation_input(
ctx: &mut aide::generate::GenContext,
operation: &mut aide::openapi::Operation,
) {
T::operation_input(ctx, operation);
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/garde/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! # Test for garde
//!
#![cfg(feature = "garde")]

use crate::tests::{ValidTest, ValidTestParameter};
Expand All @@ -15,6 +18,8 @@ use std::net::SocketAddr;
use std::ops::Deref;
use tokio::net::TcpListener;

/// ParametersGarde
///
#[derive(Clone, Deserialize, Serialize, Validate, Eq, PartialEq)]
#[cfg_attr(feature = "extra_protobuf", derive(prost::Message))]
#[cfg_attr(
Expand Down Expand Up @@ -434,6 +439,8 @@ async fn test_main() -> anyhow::Result<()> {
Ok(())
}

/// Test Executor
///
#[derive(Debug, Clone)]
pub struct TestExecutor {
client: reqwest::Client,
Expand Down Expand Up @@ -496,6 +503,7 @@ impl TestExecutor {
Ok(())
}

/// Get reqwest client reference
pub fn client(&self) -> &reqwest::Client {
&self.client
}
Expand All @@ -514,7 +522,7 @@ pub async fn check_json(type_name: &'static str, response: reqwest::Response) {
}

mod route {
pub const PATH: &str = "/path/:v0/:v1";
pub const PATH: &str = "/path/{v0}/{v1}";
pub const QUERY: &str = "/query";
pub const FORM: &str = "/form";
pub const JSON: &str = "/json";
Expand Down Expand Up @@ -692,7 +700,7 @@ mod extra {
}

// 1.3. Implement your extractor (`FromRequestParts` or `FromRequest`)
#[axum::async_trait]

impl<S> FromRequestParts<S> for ParametersGarde
where
S: Send + Sync,
Expand Down Expand Up @@ -812,11 +820,11 @@ mod extra_typed_path {
use serde::Deserialize;

pub mod route {
pub const EXTRA_TYPED_PATH: &str = "/extra_typed_path/:v0/:v1";
pub const EXTRA_TYPED_PATH: &str = "/extra_typed_path/{v0}/{v1}";
}

#[derive(Validate, TypedPath, Deserialize)]
#[typed_path("/extra_typed_path/:v0/:v1")]
#[typed_path("/extra_typed_path/{v0}/{v1}")]
pub struct TypedPathParam {
#[garde(range(min = 5, max = 10))]
v0: i32,
Expand Down
11 changes: 9 additions & 2 deletions src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ impl<T> aide::OperationInput for Valid<T>
where
T: aide::OperationInput,
{
fn operation_input(ctx: &mut aide::gen::GenContext, operation: &mut aide::openapi::Operation) {
fn operation_input(
ctx: &mut aide::generate::GenContext,
operation: &mut aide::openapi::Operation,
) {
T::operation_input(ctx, operation);
}
}
Expand Down Expand Up @@ -117,7 +120,10 @@ impl<T> aide::OperationInput for ValidEx<T>
where
T: aide::OperationInput,
{
fn operation_input(ctx: &mut aide::gen::GenContext, operation: &mut aide::openapi::Operation) {
fn operation_input(
ctx: &mut aide::generate::GenContext,
operation: &mut aide::openapi::Operation,
) {
T::operation_input(ctx, operation);
}
}
Expand Down Expand Up @@ -216,6 +222,7 @@ where
}
}

/// basic tests for validator
#[cfg(test)]
pub mod tests {
use super::*;
Expand Down
26 changes: 18 additions & 8 deletions src/validator/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! # Test for validator
//!
#![cfg(feature = "validator")]

use crate::tests::{ValidTest, ValidTestParameter};
Expand All @@ -16,6 +19,8 @@ use std::sync::Arc;
use tokio::net::TcpListener;
use validator::{Validate, ValidateArgs, ValidationError};

/// Parameters
///
#[derive(Clone, Deserialize, Serialize, Validate, Eq, PartialEq)]
#[cfg_attr(feature = "extra_protobuf", derive(prost::Message))]
#[cfg_attr(
Expand All @@ -31,6 +36,8 @@ pub struct Parameters {
v1: String,
}

/// ParametersEx
///
#[derive(Clone, Deserialize, Serialize, Validate, Eq, PartialEq)]
#[cfg_attr(feature = "extra_protobuf", derive(prost::Message))]
#[cfg_attr(
Expand Down Expand Up @@ -69,6 +76,8 @@ struct ParametersExValidationArgumentsInner {
v1_length_range: RangeInclusive<usize>,
}

/// ParametersExValidationArguments
///
#[derive(Debug, Clone, Default)]
pub struct ParametersExValidationArguments {
inner: Arc<ParametersExValidationArgumentsInner>,
Expand Down Expand Up @@ -663,6 +672,7 @@ async fn test_main() -> anyhow::Result<()> {
Ok(())
}

/// Test Executor
#[derive(Debug, Clone)]
pub struct TestExecutor {
client: reqwest::Client,
Expand Down Expand Up @@ -725,6 +735,7 @@ impl TestExecutor {
Ok(())
}

/// Get reqwest client reference
pub fn client(&self) -> &reqwest::Client {
&self.client
}
Expand All @@ -743,8 +754,8 @@ pub async fn check_json(type_name: &'static str, response: reqwest::Response) {
}

mod route {
pub const PATH: &str = "/path/:v0/:v1";
pub const PATH_EX: &str = "/path_ex/:v0/:v1";
pub const PATH: &str = "/path/{v0}/{v1}";
pub const PATH_EX: &str = "/path_ex/{v0}/{v1}";
pub const QUERY: &str = "/query";
pub const QUERY_EX: &str = "/query_ex";
pub const FORM: &str = "/form";
Expand Down Expand Up @@ -1036,7 +1047,7 @@ mod extra {
}

// 1.3. Implement your extractor (`FromRequestParts` or `FromRequest`)
#[axum::async_trait]

impl<S> FromRequestParts<S> for Parameters
where
S: Send + Sync,
Expand All @@ -1052,7 +1063,6 @@ mod extra {
}
}

#[axum::async_trait]
impl<S> FromRequestParts<S> for ParametersEx
where
S: Send + Sync,
Expand Down Expand Up @@ -1198,12 +1208,12 @@ mod extra_typed_path {
use validator::{Validate, ValidationError};

pub mod route {
pub const EXTRA_TYPED_PATH: &str = "/extra_typed_path/:v0/:v1";
pub const EXTRA_TYPED_PATH_EX: &str = "/extra_typed_path_ex/:v0/:v1";
pub const EXTRA_TYPED_PATH: &str = "/extra_typed_path/{v0}/{v1}";
pub const EXTRA_TYPED_PATH_EX: &str = "/extra_typed_path_ex/{v0}/{v1}";
}

#[derive(Validate, TypedPath, Deserialize)]
#[typed_path("/extra_typed_path/:v0/:v1")]
#[typed_path("/extra_typed_path/{v0}/{v1}")]
pub struct TypedPathParam {
#[validate(range(min = 5, max = 10))]
v0: i32,
Expand Down Expand Up @@ -1244,7 +1254,7 @@ mod extra_typed_path {
}

#[derive(Validate, TypedPath, Deserialize)]
#[typed_path("/extra_typed_path_ex/:v0/:v1")]
#[typed_path("/extra_typed_path_ex/{v0}/{v1}")]
#[validate(context = TypedPathParamExValidationArguments)]
pub struct TypedPathParamEx {
#[validate(custom(function = "validate_v0", use_context))]
Expand Down
Loading

0 comments on commit cdec7d9

Please sign in to comment.