Keats / validator

Simple validation for Rust structs
MIT License
1.91k stars 140 forks source link

Renamed property name is no longer used in the error report (0.17.0) #306

Open iensu opened 4 months ago

iensu commented 4 months ago

In 0.16.1 the validation error report uses the renamed property name when using #[serde(rename = "...")], but in 0.17.0 the original property name is used.

#[derive(Debug, serde::Deserialize, validator::Validate)]
pub struct User {
    #[validate(length(min = 1, message = "too short"))]
    #[serde(rename = "firstName")]
    pub first_name: Option<String>,
}

In 0.16.1 the error report says firstName: too short, but in 0.17.0 it's first_name: too short. This is problematic since the firstName is what is actually expected to be sent from the client, not first_name.

Keats commented 4 months ago

This has been removed for now since the support was very limited. It only worked with manual serde renaming, and not with container attributes (eg rename_all). Now that the derive has been rewritten it should be easier to implement it properly. The change was not documented in the changelog though, I've added it in my PR

iensu commented 4 months ago

I see! Yes, I noticed the lack of container attribute support. Do you plan to implement the feature in the near future?

Keats commented 4 months ago

Yes but in practice I don't know when/if i will have the time for it. I'd definitely take a PR adding that though

iensu commented 4 months ago

👍 I have no idea how complicated it would be to implement, but I'll gladly take a look at it.

iensu commented 3 days ago

Hi @Keats! I finally have some time to start looking at this. I noticed the issue is still there in 0.18.1, even though the README still states that at least field level renames should work.

I've had a more thorough look at the code now and think I have an idea how to go about implementing support for both container and field level serde renames.

Just to make sure: you haven't started looking at this yet right?

Keats commented 3 days ago

No i haven't. If it's in the README, it's something that should be removed