use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GeneratedCode {
pub files: Vec<GeneratedFile>,
}
impl GeneratedCode {
#[inline]
#[must_use]
pub fn new() -> Self {
Self { files: Vec::new() }
}
pub fn add_file(&mut self, file: GeneratedFile) {
self.files.push(file);
}
#[inline]
#[must_use]
pub fn file_count(&self) -> usize {
self.files.len()
}
#[inline]
pub fn files(&self) -> impl Iterator<Item = &GeneratedFile> {
self.files.iter()
}
}
impl Default for GeneratedCode {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GeneratedFile {
pub path: String,
pub content: String,
}
impl GeneratedFile {
#[inline]
#[must_use]
pub fn path(&self) -> &str {
&self.path
}
#[inline]
#[must_use]
pub fn content(&self) -> &str {
&self.content
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TemplateContext {
pub server_name: String,
pub server_version: String,
pub tools: Vec<ToolDefinition>,
pub metadata: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolDefinition {
pub name: String,
pub description: String,
pub input_schema: serde_json::Value,
pub typescript_name: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generated_code_new() {
let code = GeneratedCode::new();
assert_eq!(code.file_count(), 0);
}
#[test]
fn test_generated_code_default() {
let code = GeneratedCode::default();
assert_eq!(code.file_count(), 0);
}
#[test]
fn test_add_file() {
let mut code = GeneratedCode::new();
code.add_file(GeneratedFile {
path: "test.ts".to_string(),
content: "content".to_string(),
});
assert_eq!(code.file_count(), 1);
}
#[test]
fn test_tool_definition() {
let tool = ToolDefinition {
name: "test_tool".to_string(),
description: "Test".to_string(),
input_schema: serde_json::json!({"type": "object"}),
typescript_name: "testTool".to_string(),
};
assert_eq!(tool.name, "test_tool");
assert_eq!(tool.typescript_name, "testTool");
}
#[test]
fn test_template_context() {
let context = TemplateContext {
server_name: "test-server".to_string(),
server_version: "1.0.0".to_string(),
tools: vec![],
metadata: HashMap::new(),
};
assert_eq!(context.server_name, "test-server");
assert_eq!(context.tools.len(), 0);
}
}