diff --git a/schemars/src/flatten.rs b/schemars/src/flatten.rs index e55cb7fc..ba53d96f 100644 --- a/schemars/src/flatten.rs +++ b/schemars/src/flatten.rs @@ -42,23 +42,16 @@ macro_rules! impl_merge { impl Merge for Option> { fn merge(self, other: Self) -> Self { match (self.map(|x| *x), other.map(|x| *x)) { - // Perfer permissive schemas. + // Prefer permissive schemas. (Some(Schema::Bool(true)), _) => Some(Box::new(true.into())), (_, Some(Schema::Bool(true))) => Some(Box::new(true.into())), - (None, _) => None, - (_, None) => None, + (Some(Schema::Bool(false)) | None, y) => y.map(Box::new), + (x, Some(Schema::Bool(false)) | None) => x.map(Box::new), // Merge if we have two non-trivial schemas. (Some(Schema::Object(s1)), Some(Schema::Object(s2))) => { Some(Box::new(Schema::Object(s1.merge(s2)))) } - - // Perfer the more permissive schema. - (Some(s1 @ Schema::Object(_)), Some(Schema::Bool(false))) => Some(Box::new(s1)), - (Some(Schema::Bool(false)), Some(s2 @ Schema::Object(_))) => Some(Box::new(s2)), - - // Default to the null schema. - (Some(Schema::Bool(false)), Some(Schema::Bool(false))) => Some(Box::new(false.into())), } } } diff --git a/schemars/tests/expected/enum-internal.json b/schemars/tests/expected/enum-internal.json index 37739b09..b43b779a 100644 --- a/schemars/tests/expected/enum-internal.json +++ b/schemars/tests/expected/enum-internal.json @@ -28,6 +28,9 @@ "StringMap" ] } + }, + "additionalProperties": { + "type": "string" } }, {