use openapi_to_rust::{CodeGenerator, GeneratorConfig, SchemaAnalyzer};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let spec_path = Path::new("../chat-completions-client/chat-completions.json");
let spec_content = std::fs::read_to_string(spec_path)?;
let spec_value: serde_json::Value = serde_json::from_str(&spec_content)?;
let mut analyzer = SchemaAnalyzer::new(spec_value)?;
let mut analysis = analyzer.analyze()?;
let config = GeneratorConfig::default();
let generator = CodeGenerator::new(config);
let result = generator.generate(&mut analysis)?;
let lines: Vec<&str> = result.lines().collect();
let mut in_stream_response = false;
for (i, line) in lines.iter().enumerate() {
if line.contains("struct CreateChatCompletionStreamResponse") {
in_stream_response = true;
println!("Found CreateChatCompletionStreamResponse at line {}", i);
println!("\nFull struct definition:");
}
if in_stream_response {
println!("{}", line);
if line.contains("pub choices:") {
println!("\n>>> CHOICES FIELD TYPE: {}", line);
}
if *line == "}" {
in_stream_response = false;
}
}
}
println!("\nSearching for related choice types:");
for line in &lines {
if line.contains("Choice")
&& (line.contains("struct") || line.contains("enum") || line.contains("type"))
{
println!("{}", line);
}
}
Ok(())
}