schemars icon indicating copy to clipboard operation
schemars copied to clipboard

Support for the `bounds` serde attribute.

Open abizjak opened this issue 2 years ago • 0 comments

It is sometimes necessary to have either phantom types or special bounds for types for the structs. serde supports supplying custom bounds on these types so that the derived instance has useful bounds, instead of requiring all type parameters to have the Serialize/Deserialize bounds.

It does not appear that schemars honors these.

Concretely, I would like this to work

#[derive(Serialize, Deserialize)]
#[derive(JsonSchema)] 
#[serde(bound = "A: Sized")]
struct S<A> {
    x: u64,
    #[serde(skip)]
    a: PhantomData<A>
}

struct Dummy;

fn f() {
    let schema = schema_for!(S<Dummy>);
}

abizjak avatar Apr 18 '22 17:04 abizjak