api/schema.rs: avoid Option(Option( nesting

This commit is contained in:
Dietmar Maurer 2019-01-18 17:49:19 +01:00
parent 0a35462c1e
commit ffdac1af01
1 changed files with 11 additions and 1 deletions

View File

@ -283,7 +283,17 @@ impl ObjectSchema {
}
pub fn optional<S: Into<Arc<Schema>>>(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
}
}