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
636 stars 67 forks source link

Implement JsonSchemaAs for OneOrMany instead of JsonSchema #760

Closed swlynch99 closed 2 months ago

swlynch99 commented 2 months ago

Currently, there is an impl JsonSchema for WrapSchema<OneOrMany<...>>. This works fine if you only directly need OneOrMany but causes errors if you want to nest it (e.g. Option<OneOrMany<_>>).

This PR changes the impl to a JsonSchemaAs impl, which is the correct approach. I think I just missed these ones during a rebase. In any case, the change should be fully backwards compatible due to the blanket schema impl.

I have added a snapshot test. The actual snapshot doesn't matter - the real test is that the struct below compiles

#[serde_as]
#[derive(Serialize, Deserialize, JsonSchema)]
struct Test {
    #[serde_as(as = "Option<OneOrMany<_>>")]
    optional_vec: Option<Vec<String>>,
}
codecov[bot] commented 2 months ago

Codecov Report

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

Project coverage is 67.25%. Comparing base (1e4481c) to head (dee706a). Report is 21 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #760 +/- ## ========================================== + Coverage 66.55% 67.25% +0.69% ========================================== Files 38 38 Lines 2473 2452 -21 ========================================== + Hits 1646 1649 +3 + Misses 827 803 -24 ```

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

jonasbb commented 2 months ago

Thanks, that looks good :)