Skip to content

Commit 180dc31

Browse files
committed
Fix export issue
1 parent 5e36dcf commit 180dc31

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch","crates/vespertide-naming/Cargo.toml":"Patch","crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch"},"note":"Fix export issue when file has vespertide suffix","date":"2026-02-03T12:05:38.014177500Z"}

crates/vespertide-cli/src/commands/export.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ fn build_output_path(root: &Path, rel_path: &Path, orm: Orm) -> PathBuf {
111111
(file_name, "")
112112
};
113113

114+
// Strip .vespertide suffix if present (e.g., "user.vespertide" -> "user")
115+
let stem = strip_vespertide_suffix(stem);
116+
114117
let sanitized = sanitize_filename(stem);
115118
let ext = match orm {
116119
Orm::SeaOrm => "rs",
@@ -134,6 +137,12 @@ fn sanitize_filename(name: &str) -> String {
134137
.collect::<String>()
135138
}
136139

140+
/// Strip `.vespertide` suffix from a filename stem.
141+
/// E.g., "user.vespertide" -> "user", "user" -> "user"
142+
fn strip_vespertide_suffix(stem: &str) -> &str {
143+
stem.strip_suffix(".vespertide").unwrap_or(stem)
144+
}
145+
137146
fn load_models_recursive(base: &Path) -> Result<Vec<(TableDef, PathBuf)>> {
138147
let mut out = Vec::new();
139148
if !base.exists() {
@@ -151,6 +160,7 @@ fn ensure_mod_chain(root: &Path, rel_path: &Path) -> Result<()> {
151160
.filter_map(|c| {
152161
c.as_os_str()
153162
.to_str()
163+
.map(strip_vespertide_suffix)
154164
.map(|s| sanitize_filename(s).to_string())
155165
})
156166
.collect();
@@ -489,6 +499,35 @@ mod tests {
489499
assert_eq!(out_py, Path::new("src/models/users.py"));
490500
}
491501

502+
#[test]
503+
fn build_output_path_strips_vespertide_suffix() {
504+
use std::path::Path;
505+
let root = Path::new("src/models");
506+
507+
// user.vespertide.json -> user.rs (not user_vespertide.rs)
508+
let rel_path = Path::new("user.vespertide.json");
509+
let out = build_output_path(root, rel_path, Orm::SeaOrm);
510+
assert_eq!(out, Path::new("src/models/user.rs"));
511+
512+
// Nested path
513+
let rel_path2 = Path::new("blog/post.vespertide.yaml");
514+
let out2 = build_output_path(root, rel_path2, Orm::SeaOrm);
515+
assert_eq!(out2, Path::new("src/models/blog/post.rs"));
516+
517+
// Python export
518+
let out_py = build_output_path(root, rel_path, Orm::SqlAlchemy);
519+
assert_eq!(out_py, Path::new("src/models/user.py"));
520+
}
521+
522+
#[rstest]
523+
#[case("user.vespertide", "user")]
524+
#[case("user", "user")]
525+
#[case("user.vespertide.extra", "user.vespertide.extra")]
526+
#[case("", "")]
527+
fn test_strip_vespertide_suffix(#[case] input: &str, #[case] expected: &str) {
528+
assert_eq!(strip_vespertide_suffix(input), expected);
529+
}
530+
492531
#[test]
493532
fn build_output_path_handles_special_path_components() {
494533
use std::path::Path;

0 commit comments

Comments
 (0)