Skip to content

Commit 1c8dd5a

Browse files
committed
Fix description issue
1 parent 427d6fb commit 1c8dd5a

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"Cargo.toml":"Patch"},"note":"Fix description issue","date":"2026-04-07T09:36:28.999142800Z"}

crates/vespera_macro/src/parser/schema/serde_attrs.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ pub fn extract_doc_comment(attrs: &[syn::Attribute]) -> Option<String> {
1717
}) = &meta_nv.value
1818
{
1919
let line = lit_str.value();
20-
// Trim leading space that rustdoc adds.
21-
// Also handle `" / "` prefix that can appear when doc-comment
22-
// markers leak through TokenStream → string → parse roundtrips.
20+
// Strip `" / "` or `"/ "` prefixes that can appear when doc-comment
21+
// markers leak through TokenStream → string → parse roundtrips,
22+
// then trim any remaining whitespace.
2323
let trimmed = line
2424
.strip_prefix(" / ")
25-
.or_else(|| line.strip_prefix(' '))
26-
.unwrap_or(&line);
25+
.or_else(|| line.strip_prefix("/ "))
26+
.unwrap_or(&line)
27+
.trim();
2728
doc_lines.push(trimmed.to_string());
2829
}
2930
}

crates/vespera_macro/src/parser/schema/struct_schema.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,31 @@ mod tests {
349349
}
350350
}
351351

352+
#[test]
353+
fn test_parse_struct_to_schema_description_strips_slash_prefix() {
354+
// When doc attributes have "/ " prefix (without leading space), descriptions should be clean.
355+
// This can happen in certain TokenStream roundtrip scenarios.
356+
let struct_item: syn::ItemStruct = syn::parse_str(
357+
r#"
358+
#[doc = "/ Struct description"]
359+
struct Admin {
360+
#[doc = "/ Field description"]
361+
id: i32,
362+
}
363+
"#,
364+
)
365+
.unwrap();
366+
let schema = parse_struct_to_schema(&struct_item, &HashSet::new(), &HashMap::new());
367+
assert_eq!(
368+
schema.description,
369+
Some("Struct description".to_string())
370+
);
371+
let props = schema.properties.unwrap();
372+
if let SchemaRef::Inline(id_schema) = props.get("id").unwrap() {
373+
assert_eq!(id_schema.description, Some("Field description".to_string()));
374+
}
375+
}
376+
352377
#[test]
353378
fn test_parse_struct_to_schema_with_flatten() {
354379
let struct_item: syn::ItemStruct = syn::parse_str(

crates/vespera_macro/src/route/utils.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ pub fn extract_doc_comment(attrs: &[syn::Attribute]) -> Option<String> {
1414
}) = &meta_nv.value
1515
{
1616
let line = lit_str.value();
17-
// Trim leading space that rustdoc adds.
18-
// Also handle `" / "` prefix that can appear when doc-comment
19-
// markers leak through TokenStream → string → parse roundtrips.
17+
// Strip `" / "` or `"/ "` prefixes that can appear when doc-comment
18+
// markers leak through TokenStream → string → parse roundtrips,
19+
// then trim any remaining whitespace.
2020
let trimmed = line
2121
.strip_prefix(" / ")
22-
.or_else(|| line.strip_prefix(' '))
23-
.unwrap_or(&line);
22+
.or_else(|| line.strip_prefix("/ "))
23+
.unwrap_or(&line)
24+
.trim();
2425
doc_lines.push(trimmed.to_string());
2526
}
2627
}

0 commit comments

Comments
 (0)