Skip to content

Commit

Permalink
Fix "null" default not being set on schema (#296)
Browse files Browse the repository at this point in the history
Fixes #295
  • Loading branch information
GREsau authored May 23, 2024
1 parent 7ecaa7f commit a9a9c7e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schemars/src/_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub mod metadata {
add_metadata_fn!(add_deprecated, deprecated, bool);
add_metadata_fn!(add_read_only, read_only, bool);
add_metadata_fn!(add_write_only, write_only, bool);
add_metadata_fn!(add_default, default, Value);
add_metadata_fn!(add_default, default, Option<Value>);

pub fn add_examples<I: IntoIterator<Item = Value>>(schema: Schema, examples: I) -> Schema {
let mut schema_obj = schema.into_object();
Expand Down
1 change: 1 addition & 0 deletions schemars/tests/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ where
struct MyStruct {
my_int: i32,
my_bool: bool,
my_optional_string: Option<String>,
#[serde(serialize_with = "custom_serialize")]
my_struct2: MyStruct2,
#[serde(
Expand Down
7 changes: 7 additions & 0 deletions schemars/tests/expected/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"default": false,
"type": "boolean"
},
"my_optional_string": {
"default": null,
"type": [
"string",
"null"
]
},
"my_struct2": {
"default": "i:0 b:false",
"allOf": [
Expand Down

0 comments on commit a9a9c7e

Please sign in to comment.