Skip to content

Commit 1de30e0

Browse files
authored
Merge pull request #63 from dev-five-git/add-description
Support description
2 parents df9f977 + 20cef62 commit 1de30e0

File tree

14 files changed

+672
-86
lines changed

14 files changed

+672
-86
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"crates/vespera_macro/Cargo.toml":"Patch","crates/vespera/Cargo.toml":"Patch","crates/vespera_core/Cargo.toml":"Patch"},"note":"Support description","date":"2026-02-03T18:15:43.339445900Z"}

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vespera_core/src/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub enum StringFormat {
7474
}
7575

7676
/// JSON Schema definition
77-
#[derive(Debug, Clone, Serialize, Deserialize)]
77+
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7878
#[serde(rename_all = "camelCase")]
7979
pub struct Schema {
8080
/// Schema reference ($ref) - if present, other fields are ignored

crates/vespera_macro/src/lib.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,4 +2058,86 @@ pub fn get_users() -> String {
20582058
// It should return a PathBuf (either from src/nonexistent... or just the folder name)
20592059
assert!(result.to_string_lossy().contains("nonexistent_folder_xyz"));
20602060
}
2061+
2062+
// ========== Tests for extract_schema_name_attr ==========
2063+
2064+
#[test]
2065+
fn test_extract_schema_name_attr_with_name() {
2066+
let attrs: Vec<syn::Attribute> = syn::parse_quote! {
2067+
#[schema(name = "CustomName")]
2068+
};
2069+
let result = extract_schema_name_attr(&attrs);
2070+
assert_eq!(result, Some("CustomName".to_string()));
2071+
}
2072+
2073+
#[test]
2074+
fn test_extract_schema_name_attr_without_name() {
2075+
let attrs: Vec<syn::Attribute> = syn::parse_quote! {
2076+
#[derive(Debug)]
2077+
};
2078+
let result = extract_schema_name_attr(&attrs);
2079+
assert_eq!(result, None);
2080+
}
2081+
2082+
#[test]
2083+
fn test_extract_schema_name_attr_empty_schema() {
2084+
let attrs: Vec<syn::Attribute> = syn::parse_quote! {
2085+
#[schema]
2086+
};
2087+
let result = extract_schema_name_attr(&attrs);
2088+
assert_eq!(result, None);
2089+
}
2090+
2091+
#[test]
2092+
fn test_extract_schema_name_attr_with_other_attrs() {
2093+
let attrs: Vec<syn::Attribute> = syn::parse_quote! {
2094+
#[derive(Clone)]
2095+
#[schema(name = "MySchema")]
2096+
#[serde(rename_all = "camelCase")]
2097+
};
2098+
let result = extract_schema_name_attr(&attrs);
2099+
assert_eq!(result, Some("MySchema".to_string()));
2100+
}
2101+
2102+
// ========== Tests for process_derive_schema ==========
2103+
2104+
#[test]
2105+
fn test_process_derive_schema_simple() {
2106+
let input: syn::DeriveInput = syn::parse_quote! {
2107+
struct User {
2108+
id: i32,
2109+
name: String,
2110+
}
2111+
};
2112+
let (metadata, tokens) = process_derive_schema(&input);
2113+
assert_eq!(metadata.name, "User");
2114+
assert!(metadata.definition.contains("User"));
2115+
let tokens_str = tokens.to_string();
2116+
assert!(tokens_str.contains("SchemaBuilder"));
2117+
}
2118+
2119+
#[test]
2120+
fn test_process_derive_schema_with_custom_name() {
2121+
let input: syn::DeriveInput = syn::parse_quote! {
2122+
#[schema(name = "CustomUserSchema")]
2123+
struct User {
2124+
id: i32,
2125+
}
2126+
};
2127+
let (metadata, _) = process_derive_schema(&input);
2128+
assert_eq!(metadata.name, "CustomUserSchema");
2129+
}
2130+
2131+
#[test]
2132+
fn test_process_derive_schema_with_generics() {
2133+
let input: syn::DeriveInput = syn::parse_quote! {
2134+
struct Container<T> {
2135+
value: T,
2136+
}
2137+
};
2138+
let (metadata, tokens) = process_derive_schema(&input);
2139+
assert_eq!(metadata.name, "Container");
2140+
let tokens_str = tokens.to_string();
2141+
assert!(tokens_str.contains("< T >") || tokens_str.contains("<T>"));
2142+
}
20612143
}

0 commit comments

Comments
 (0)