Keats / validator

Simple validation for Rust structs
MIT License
1.97k stars 141 forks source link

Code cannot be overridden for custom validator #284

Open akkie opened 8 months ago

akkie commented 8 months ago

The documentation indicates that the code can be overridden for a custom validator.

https://github.com/akkie/validator?tab=readme-ov-file#message-and-code

But this doesn't work. There is also no test for it.

nMessage commented 6 months ago

Specifying a custom Error code for Custom Validation checks fails. eg

#[derive(Validate, Deserialize)]
pub struct ExampleStruct {
    #[validate(custom = "custom_check", code = "Custom error")]
    foo: String,
}

When using a custom validator like this, when a code is specified, Compiler errors with "validate not implemented for this struct"

The bellow example works just fine however.

#[derive(Validate, Deserialize)]
pub struct ExampleStruct {
    #[validate(custom = "custom_check")
    foo: String,
}
Keats commented 6 months ago

Can you check with https://github.com/Keats/validator/pull/249 ?