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

`#[serde_as(deserialize_as = …)]` generates `#[schemars(deserialize_with(…))]`, which is invalid #735

Closed sivizius closed 4 months ago

sivizius commented 4 months ago

Due to https://github.com/jonasbb/serde_with/blob/master/serde_with_macros/src/lib.rs#L814, a #[serde_as(deserialize_as = …)] will generate #[schemars(deserialize_with(…))] if feature schemars_0_8 is enabled, but https://github.com/GREsau/schemars/blob/master/schemars_derive/src/attr/schemars_to_serde.rs#L8-L31 does not contain deserialize_with, only serialize_with. Generation of #[schemars(deserialize_with(…))] thus results in an compiler error. I suggest to use #[schemars(schema_with = "…")].

The error I get looks like this:

error: unknown schemars attribute `deserialize_with`
  --> cherub/src/foo/bar.rs:23:1
   |
23 | #[serde_as]
jonasbb commented 4 months ago

Thanks for finding this problem. Indeed, deserialize_with for schemars is not supported. It seems that serialize_with is only "supported" in that it doesn't cause compilation failures, but it won't change the generated schema. The problem is fixed in v3.8.1.