-
-
Notifications
You must be signed in to change notification settings - Fork 284
Open
Description
This does not compile:
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, JsonSchema)]
struct Foo<T> {
#[serde(default)]
foo: T,
}The generated code contains <T>::default, generated here:
schemars/schemars_derive/src/schema_exprs.rs
Line 778 in 76d4bc3
| SerdeDefault::Default => quote!(<#ty>::default()), |
but it doesn't add T: Default into the where clause, so the code doesn't compile.
Serde's Deserialize derive adds a T: Default bound automatically (so Foo can only be deserialized if T is Default). Schemars should do the same.
Manually adding the bound fixes it, of course:
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, JsonSchema)]
#[schemars(bound = "T: JsonSchema + Default")]
struct Foo<T> {
#[serde(default)]
foo: T,
}Metadata
Metadata
Assignees
Labels
No labels