From ffdac1af01f16ab679b4bbd87f1126e54d338880 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 18 Jan 2019 17:49:19 +0100 Subject: [PATCH] api/schema.rs: avoid Option(Option( nesting --- src/api/schema.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/api/schema.rs b/src/api/schema.rs index 9274dbcf..14eeee8a 100644 --- a/src/api/schema.rs +++ b/src/api/schema.rs @@ -283,7 +283,17 @@ impl ObjectSchema { } pub fn optional>>(mut self, name: &'static str, schema: S) -> Self { - self.properties.insert(name, Arc::new(Schema::Option(schema.into()))); + let schema = schema.into(); + let is_option = match schema.as_ref() { + Schema::Option(_) => true, + _ => false, + }; + if is_option { + self.properties.insert(name, schema); + } else { + self.properties.insert(name, Arc::new(Schema::Option(schema))); + } + self } }