Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support #[serde(skip_serializing_if = "path")] #26

Closed
RagibHasin opened this issue Apr 10, 2020 · 4 comments
Closed

support #[serde(skip_serializing_if = "path")] #26

RagibHasin opened this issue Apr 10, 2020 · 4 comments

Comments

@RagibHasin
Copy link

Currently this causes an error like

mismatched types
expected reference &std::option::Option<_>
found reference &<task::Task as schemars::JsonSchema>::json_schema::_SchemarsDefaultSerialize<std::option::Option<std::time::Duration>>

I think it should mark that field as not required.

Thanks in advance.

@RagibHasin
Copy link
Author

My the field causing error looks like,

    #[schemars(with = "Option<String>")]
    #[serde(
        default,
        with = "duration_utils::opt",
        skip_serializing_if = "Option::is_none"
    )]
    pub duration: Option<StdDuration>,

removing any of the serde attributes makes it OK. I don't get what is wrong.

@GREsau
Copy link
Owner

GREsau commented Apr 10, 2020

Yep that's definitely a bug in schemars, I'll try to get a fix out asap

GREsau added a commit that referenced this issue Apr 11, 2020
Previously whenever a field with a default value has both `skip_serializing_if` and `with`/`serialize_with` attributes, the value would be converted to a type that performs the custom serialization before checking if it should be serialized. This would cause the wrong type to be given to the skip_serializing_if function, causing a compile error.

Issue #26
@GREsau
Copy link
Owner

GREsau commented Apr 11, 2020

This should be fixed in v0.7.1 which is now on crates.io: https://crates.io/crates/schemars/0.7.1

@RagibHasin could you please re-test and let me know if it works for you?

@RagibHasin
Copy link
Author

Thanks for that quick a reply! It solved the problem. I was taking a break for a while. So, sorry for my being late.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants