diff --git a/CHANGELOG.md b/CHANGELOG.md index cc3c651..5c6a781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,16 @@ ### Fixed +## axum-valid 0.8.0 (2023-09-19) + +### Added + +* Upgraded `axum-extra` dependencies to version 0.8.0 + +### Changed + +### Fixed + ## axum-valid 0.7.0 (2023-09-12) ### Added diff --git a/Cargo.toml b/Cargo.toml index ef1c355..3fd6121 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axum-valid" -version = "0.7.0" +version = "0.8.0" description = "Provide validator extractor for your axum application." authors = ["GengTeng "] license = "MIT" @@ -24,8 +24,8 @@ edition = "2021" features = ["all_types"] [dependencies] -axum = { version = "0.6.18", default-features = false } -validator = "0.16.0" +axum = { version = "0.6.20", default-features = false } +validator = "0.16.1" [dependencies.axum_typed_multipart] version = "0.9.0" @@ -43,7 +43,7 @@ default-features = false optional = true [dependencies.axum-extra] -version = "0.7.6" +version = "0.8.0" default-features = false optional = true @@ -58,7 +58,7 @@ validator = { version = "0.16.0", features = ["derive"] } serde_json = "1.0.104" serde_yaml = "0.9.25" mime = "0.3.17" -prost = "0.11.9" +prost = "0.12.1" once_cell = "1.18.0" rmp-serde = "1.1.2" diff --git a/README.md b/README.md index b30e165..ca5d828 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ use validator::Validate; use serde::Deserialize; use axum_valid::Valid; use axum::extract::Query; -use axum::Json; +use axum::{Json, Router}; +use axum::routing::{get, post}; #[derive(Debug, Validate, Deserialize)] pub struct Pager { @@ -59,7 +60,7 @@ async fn main() -> anyhow::Result<()> { When validation errors occur, the extractor will automatically return 400 with validation errors as the HTTP message body. -To see how each extractor can be used with `Valid`, please refer to the example in the [documentation](#modules) of the corresponding module. +To see how each extractor can be used with `Valid`, please refer to the example in the [documentation](https://docs.rs/axum-valid) of the corresponding module. ## Features @@ -84,6 +85,11 @@ To see how each extractor can be used with `Valid`, please refer to the example | into_json | Validation errors will be serialized into JSON format and returned as the HTTP body | ❌ | ✅ | ✅ | | full | Enables all features | ❌ | ✅ | ✅ | +## Compatibility + +* axum-valid 0.7.x works with axum-extra v0.7.x +* axum-valid 0.8.x works with axum-extra v0.8.x + ## License This project is licensed under the MIT License. diff --git a/src/extra.rs b/src/extra.rs index 2bd85ab..faafa43 100644 --- a/src/extra.rs +++ b/src/extra.rs @@ -1,18 +1,29 @@ -//! # Support for `Cached` and `WithRejection` +//! # Support for extractors from `axum-extra` //! //! ## Feature //! //! Enable the `extra` feature to use `Valid>`, `Valid>` and `WithRejection, R>`. //! -//! ## `Valid>` +//! ## Modules //! -//! ### Usage +//! * [`self`] : `Cache` +//! * [`self`] : `WithRejection` +//! * [`form`] : `Form` +//! * [`protobuf`] : `Protobuf` +//! * [`query`] : `Query` +//! * [`typed_path`] : `T: TypedPath` +//! +//! ## `Cached` and `WithRejection` +//! +//! ### `Valid>` +//! +//! #### Usage //! //! 0. Implement your own extractor `T`. //! 1. Implement `Clone` and `Validate` for your extractor type `T`. //! 2. In your handler function, use `Valid>` as some parameter's type. //! -//! ### Example +//! #### Example //! //! ```no_run //! use axum::extract::FromRequestParts; @@ -63,15 +74,15 @@ //! } //! ``` //! -//! ## `Valid>` +//! ### `Valid>` //! -//! ### Usage +//! #### Usage //! //! 0. Implement your own extractor `T` and rejection type `R`. //! 1. Implement `Validate` for your extractor type `T`. //! 2. In your handler function, use `Valid>` as some parameter's type. //! -//! ### Example +//! #### Example //! //! ```no_run //! use axum::extract::FromRequestParts; @@ -128,16 +139,16 @@ //! } //! ``` //! -//! ## `WithRejection, R>` +//! ### `WithRejection, R>` //! -//! ### Usage +//! #### Usage //! //! 0. Implement your own extractor `T` and rejection type `R`. //! 1. Implement `Validate` and `HasValidate` for your extractor type `T`. //! 2. Implement `From>` for `R`. //! 3. In your handler function, use `WithRejection, R>` as some parameter's type. //! -//! ### Example +//! #### Example //! //! ```no_run //! use axum::extract::FromRequestParts; diff --git a/src/lib.rs b/src/lib.rs index 709f0c2..0fb3202 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,17 @@ pub const VALIDATION_ERROR_STATUS: StatusCode = StatusCode::UNPROCESSABLE_ENTITY #[cfg(not(feature = "422"))] pub const VALIDATION_ERROR_STATUS: StatusCode = StatusCode::BAD_REQUEST; -/// Valid entity extractor +/// # `Valid` data extractor +/// +/// This extractor can be used in combination with axum's extractors like +/// Json, Form, Query, Path, etc to validate their inner data automatically. +/// It can also work with custom extractors that implement the `HasValidate` trait. +/// +/// See the docs for each integration module to find examples of using +/// `Valid` with that extractor: +/// +/// For examples with custom extractors, check out the `tests/custom.rs` file. +/// #[derive(Debug, Clone, Copy, Default)] pub struct Valid(pub E);