-
-
Notifications
You must be signed in to change notification settings - Fork 284
Open
Description
Although using #[serde(default)] does work, it's usually cleaner for enums to use the Rust built-in Default derive, with #[default] on a key. Schemars does not currently detect this:
use schemars::JsonSchema;
#[derive(Debug, JsonSchema, Default)]
enum Enum {
Foo,
#[default]
Bar
}
fn main() {
let val = Enum::default();
println!("{:?}", val); // "Bar"
let schema = schemars::schema_for!(Enum);
println!(
"{}",
serde_json::to_string_pretty(&schema).expect("to be serializable")
);
}This results in the following schema, with no default key present:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Enum",
"type": "string",
"enum": [
"Foo",
"Bar"
]
}Metadata
Metadata
Assignees
Labels
No labels