Skip to content

Commit 913e9be

Browse files
Copilotjosecelano
andcommitted
fix: [#40] make template validation extensible for future formats
- Add template_type parameter to validate_output_path - Use template_type.file_extension() instead of hardcoded 'json' - Improve error messages to include template type name - Make code ready for TOML/YAML support without changes Co-authored-by: josecelano <58816+josecelano@users.noreply.github.com>
1 parent 72d08b1 commit 913e9be

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/infrastructure/templates/provider.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl TemplateProvider {
9595
})?;
9696

9797
// Validate output path
98-
Self::validate_output_path(output_path)?;
98+
Self::validate_output_path(output_path, template_type)?;
9999

100100
// Create parent directories if they don't exist
101101
if let Some(parent) = output_path.parent() {
@@ -191,7 +191,7 @@ impl TemplateProvider {
191191
}
192192

193193
/// Validate that the output path is suitable for template generation
194-
fn validate_output_path(path: &Path) -> Result<(), TemplateError> {
194+
fn validate_output_path(path: &Path, template_type: TemplateType) -> Result<(), TemplateError> {
195195
// Check if path already exists and is not a file
196196
if path.exists() && !path.is_file() {
197197
return Err(TemplateError::InvalidOutputPath {
@@ -200,14 +200,17 @@ impl TemplateProvider {
200200
});
201201
}
202202

203-
// Validate file extension matches template type (JSON)
203+
// Validate file extension matches template type
204+
let expected_extension = template_type.file_extension();
204205
if let Some(extension) = path.extension() {
205-
if extension != "json" {
206+
if extension != expected_extension {
206207
return Err(TemplateError::InvalidOutputPath {
207208
path: path.to_path_buf(),
208209
reason: format!(
209-
"File extension '{}' does not match JSON template type",
210-
extension.to_string_lossy()
210+
"File extension '{}' does not match {} template type (expected '{}')",
211+
extension.to_string_lossy(),
212+
template_type,
213+
expected_extension
211214
),
212215
});
213216
}

0 commit comments

Comments
 (0)