Refactor apply_metadata() to remove clone
This commit is contained in:
parent
39918ba06c
commit
d7c9222330
3 changed files with 10 additions and 13 deletions
|
@ -343,10 +343,12 @@ impl SchemaGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO should this take a Schema instead of SchemaObject?
|
||||
pub(crate) fn apply_metadata(&self, schema: &mut SchemaObject, metadata: Metadata) {
|
||||
self.make_extensible(schema);
|
||||
// TODO get rid of the clone
|
||||
schema.metadata = Some(Box::new(metadata)).merge(schema.metadata.clone());
|
||||
pub(crate) fn apply_metadata(&self, schema: Schema, metadata: Metadata) -> Schema {
|
||||
let mut schema_obj = schema.into();
|
||||
|
||||
self.make_extensible(&mut schema_obj);
|
||||
schema_obj.metadata = Some(Box::new(metadata)).merge(schema_obj.metadata);
|
||||
|
||||
Schema::Object(schema_obj)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,9 +67,7 @@ impl<T: JsonSchema> JsonSchema for Option<T> {
|
|||
let mut schema = gen.subschema_for::<Self>();
|
||||
|
||||
if let Some(metadata) = metadata {
|
||||
let mut schema_obj = schema.into();
|
||||
gen.apply_metadata(&mut schema_obj, metadata);
|
||||
schema = Schema::Object(schema_obj);
|
||||
schema = gen.apply_metadata(schema, metadata);
|
||||
}
|
||||
|
||||
let object = parent.object();
|
||||
|
|
|
@ -37,8 +37,7 @@ fn main() {
|
|||
"type": "object",
|
||||
"required": [
|
||||
"my_bool",
|
||||
"my_int",
|
||||
"my_nullable_enum"
|
||||
"my_int"
|
||||
],
|
||||
"properties": {
|
||||
"my_bool": {
|
||||
|
@ -303,9 +302,7 @@ pub trait JsonSchema {
|
|||
let mut schema = gen.subschema_for::<Self>();
|
||||
|
||||
if let Some(metadata) = metadata {
|
||||
let mut schema_obj = schema.into();
|
||||
gen.apply_metadata(&mut schema_obj, metadata);
|
||||
schema = Schema::Object(schema_obj);
|
||||
schema = gen.apply_metadata(schema, metadata);
|
||||
}
|
||||
|
||||
let object = parent.object();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue