yassun7010 / serde_valid

JSON Schema based validation tool using serde.
MIT License
45 stars 10 forks source link

Forced field validation when the field is empty? #53

Closed vsilent closed 7 months ago

vsilent commented 7 months ago

It looks like field is validated anyway, even it's wrapped with the Option, is it default behaviour or a bug? for example:

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Validate)]
pub struct Port {
    #[validate(pattern = r"^\d{2,6}+$")]
    pub host_port: Option<String>,

I expected this field not to be validated when empty or should I use rules for that case ?

vsilent commented 7 months ago

Sorry my bad, not an issue, because I get Some("") not None