jonasbb / serde_with

This crate provides custom de/serialization helpers to use in combination with serde's `with`-annotation and with the improved `serde_as`-annotation.
https://docs.rs/serde_with
Apache License 2.0
663 stars 72 forks source link

Avoid emitting a `#[schemars(with = "...")]` annotation when one already exists #682

Closed swlynch99 closed 9 months ago

swlynch99 commented 9 months ago

The #[schemars] annotation emitted by #[serde_as] will cause errors if the user has already added an existing #[schemars(with = ...)] annotation. This ends up being rather annoying since there's no way to work around the error other than to manually expand what #[serde_as] does.

I ended up running into this when I was trying to convert some of my existing code to use the new integration instead of manually sticking #[schemars(with = "blah")] everywhere.

This PR fixes the issue by making #[serde_as] avoid emitting the schemars attribute if there is an existing one of the field that specifies any one of

The actual code is a bit more involved (e.g. serialize_as doesn't conflict with #[schemars(deserialize_with = "...")]) but that's the gist of it.

I have also included a test case to validate that this works as expected.

codecov[bot] commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (6ecde3c) 65.16% compared to head (1c9131f) 65.16%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #682 +/- ## ======================================= Coverage 65.16% 65.16% ======================================= Files 38 38 Lines 2268 2268 ======================================= Hits 1478 1478 Misses 790 790 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.