Skip to content

Commit 167edf3

Browse files
authored
Accept comments on both transparent struct and its field (#448)
1 parent 75f670a commit 167edf3

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

schemars/tests/integration/transparent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn transparent_struct() {
1818
#[serde(transparent)]
1919
/// A doc comment
2020
pub struct TransparentStructWithDoc {
21+
/// Another doc comment (ignored)
2122
inner: String,
2223
}
2324

schemars_derive/src/attr/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,18 @@ impl CommonAttrs {
183183
let mut title = self.title.as_ref().map(ToTokens::to_token_stream);
184184
let mut description = self.description.as_ref().map(ToTokens::to_token_stream);
185185
if let Some(doc) = &self.doc {
186-
if title.is_none() || description.is_none() {
187-
mutators.push(quote!{
188-
const title_and_description: (&str, &str) = schemars::_private::get_title_and_description(#doc);
189-
});
190-
title.get_or_insert_with(|| quote!(title_and_description.0));
191-
description.get_or_insert_with(|| quote!(title_and_description.1));
192-
}
186+
title.get_or_insert_with(|| {
187+
quote!({
188+
const TITLE: &str = schemars::_private::get_title_and_description(#doc).0;
189+
TITLE
190+
})
191+
});
192+
description.get_or_insert_with(|| {
193+
quote!({
194+
const DESCRIPTION: &str = schemars::_private::get_title_and_description(#doc).1;
195+
DESCRIPTION
196+
})
197+
});
193198
}
194199
if let Some(title) = title {
195200
mutators.push(quote! {

0 commit comments

Comments
 (0)