diff --git a/schemars/src/_private.rs b/schemars/src/_private.rs index 657244b..5b03178 100644 --- a/schemars/src/_private.rs +++ b/schemars/src/_private.rs @@ -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); pub fn add_examples>(schema: Schema, examples: I) -> Schema { let mut schema_obj = schema.into_object(); diff --git a/schemars/tests/default.rs b/schemars/tests/default.rs index fbc1033..ab489f5 100644 --- a/schemars/tests/default.rs +++ b/schemars/tests/default.rs @@ -30,6 +30,7 @@ where struct MyStruct { my_int: i32, my_bool: bool, + my_optional_string: Option, #[serde(serialize_with = "custom_serialize")] my_struct2: MyStruct2, #[serde( diff --git a/schemars/tests/expected/default.json b/schemars/tests/expected/default.json index aefef83..4155d53 100644 --- a/schemars/tests/expected/default.json +++ b/schemars/tests/expected/default.json @@ -12,6 +12,13 @@ "default": false, "type": "boolean" }, + "my_optional_string": { + "default": null, + "type": [ + "string", + "null" + ] + }, "my_struct2": { "default": "i:0 b:false", "allOf": [