Skip to content

Commit

Permalink
Merge metadata setters and transform applications if they're both spe…
Browse files Browse the repository at this point in the history
…cified
  • Loading branch information
GREsau committed Aug 12, 2024
1 parent eb30777 commit faf15e7
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions schemars_derive/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,18 @@ pub struct SchemaMetadata<'a> {
impl<'a> SchemaMetadata<'a> {
pub fn apply_to_schema(&self, schema_expr: &mut TokenStream) {
let setters = self.make_setters();
if !setters.is_empty() {
*schema_expr = quote! {{
let mut schema = #schema_expr;
#(#setters)*
schema
}}
}
if !self.transforms.is_empty() {
if !setters.is_empty() || !self.transforms.is_empty() {
let apply_transforms = self.transforms.iter().map(|t| {
quote_spanned! {t.span()=>
schemars::transform::Transform::transform(&mut #t, &mut schema);
}
});
*schema_expr = quote! {{
let mut schema = #schema_expr;
#(#setters)*
#(#apply_transforms)*
schema
}};
}}
}
}

Expand Down

0 comments on commit faf15e7

Please sign in to comment.