Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_ikN3nuiD4ptMqueTJBAjI.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"Cargo.toml":"Patch"},"note":"Fix description issue","date":"2026-04-07T09:36:28.999142800Z"}
11 changes: 6 additions & 5 deletions crates/vespera_macro/src/parser/schema/serde_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ pub fn extract_doc_comment(attrs: &[syn::Attribute]) -> Option<String> {
}) = &meta_nv.value
{
let line = lit_str.value();
// Trim leading space that rustdoc adds.
// Also handle `" / "` prefix that can appear when doc-comment
// markers leak through TokenStream → string → parse roundtrips.
// Strip `" / "` or `"/ "` prefixes that can appear when doc-comment
// markers leak through TokenStream → string → parse roundtrips,
// then trim any remaining whitespace.
let trimmed = line
.strip_prefix(" / ")
.or_else(|| line.strip_prefix(' '))
.unwrap_or(&line);
.or_else(|| line.strip_prefix("/ "))
.unwrap_or(&line)
.trim();
doc_lines.push(trimmed.to_string());
}
}
Expand Down
25 changes: 25 additions & 0 deletions crates/vespera_macro/src/parser/schema/struct_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,31 @@ mod tests {
}
}

#[test]
fn test_parse_struct_to_schema_description_strips_slash_prefix() {
// When doc attributes have "/ " prefix (without leading space), descriptions should be clean.
// This can happen in certain TokenStream roundtrip scenarios.
let struct_item: syn::ItemStruct = syn::parse_str(
r#"
#[doc = "/ Struct description"]
struct Admin {
#[doc = "/ Field description"]
id: i32,
}
"#,
)
.unwrap();
let schema = parse_struct_to_schema(&struct_item, &HashSet::new(), &HashMap::new());
assert_eq!(
schema.description,
Some("Struct description".to_string())
);
let props = schema.properties.unwrap();
if let SchemaRef::Inline(id_schema) = props.get("id").unwrap() {
assert_eq!(id_schema.description, Some("Field description".to_string()));
}
}

#[test]
fn test_parse_struct_to_schema_with_flatten() {
let struct_item: syn::ItemStruct = syn::parse_str(
Expand Down
11 changes: 6 additions & 5 deletions crates/vespera_macro/src/route/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ pub fn extract_doc_comment(attrs: &[syn::Attribute]) -> Option<String> {
}) = &meta_nv.value
{
let line = lit_str.value();
// Trim leading space that rustdoc adds.
// Also handle `" / "` prefix that can appear when doc-comment
// markers leak through TokenStream → string → parse roundtrips.
// Strip `" / "` or `"/ "` prefixes that can appear when doc-comment
// markers leak through TokenStream → string → parse roundtrips,
// then trim any remaining whitespace.
let trimmed = line
.strip_prefix(" / ")
.or_else(|| line.strip_prefix(' '))
.unwrap_or(&line);
.or_else(|| line.strip_prefix("/ "))
.unwrap_or(&line)
.trim();
doc_lines.push(trimmed.to_string());
}
}
Expand Down