gengteng / axum-valid

axum-valid is a library that provides data validation extractors for the Axum web framework. It integrates validator, garde and validify, three popular validation crates in the Rust ecosystem, to offer convenient validation and data handling extractors for Axum applications.
MIT License
105 stars 5 forks source link

`validator` setup instructions cause version skew #20

Closed antifuchs closed 7 months ago

antifuchs commented 7 months ago

Symptoms

Just spent a bunch of minutes with a real head-scratcher of a problem: I'd followed the instructions on the readme for getting set up with validator, and using the following (abbreviated) code:

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash, Validate)]
struct Pagination {
    last_seen: Option<BookmarkId>,
    #[validate(range(min = 1, max = 500))]
    per_page: Option<u16>,
}

assert_impl_all!(Pagination: Validate);

async fn list_bookmarks(
    Valid(Query(pagination)): Valid<Query<Pagination>>,
    mut txn: DbTransaction,
) -> Result<Json<Vec<AnnotatedBookmark>>, (StatusCode, Json<ApiError>)> {
    // ...
}

Got the following error:

66 |     Valid(Query(pagination)): Valid<Query<Pagination>>,
   |                               ^^^^^ the trait `FromRequest<(), _>` is not implemented for `axum_valid::Valid<axum::extract::Query<Pagination>>`

which is a really weird one to receive when you just asserted that the trait is implemented.

What's wrong

However: axum-valid pulls in a different version of validator than cargo add validator does. So my lockfile has axum-valid's validator crate pinned at 0.16.1, while my project has it at 0.17.0. That results in incompatible types.

What to do

I'd suggest bumping the validator dependency, or updating the readme to match the version of validator required in this crate.

gengteng commented 7 months ago

Thanks for your feedback! The new version of validator introduces significant changes, particularly with the use of arguments in validations, so upgrading axum-valid to be compatible with this new version will take some time for adjustments and testing. I'll work on this update as quickly as possible, but ensuring everything works smoothly might take a bit longer. Please stay tuned, and thank you for your understanding and patience!

gengteng commented 7 months ago

Please try the latest version of axum-valid (0.17.0), now supporting validator of 0.17.0. Thanks!