1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use openapi_to_rust::{CodeGenerator, GeneratorConfig, SchemaAnalyzer};
use serde_json::json;
fn main() {
let spec = json!({
"openapi": "3.0.0",
"info": {
"title": "Chat API",
"version": "1.0.0"
},
"components": {
"schemas": {
"ChatMessage": {
"type": "object",
"description": "A chat message from a user or assistant",
"properties": {
"role": {
"type": "string",
"enum": ["user", "assistant", "system"]
},
"content": {
"type": "string"
},
"timestamp": {
"type": "integer",
"format": "int64"
}
},
"required": ["role", "content"]
},
"ChatRequest": {
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChatMessage"
}
},
"model": {
"type": "string"
},
"temperature": {
"type": "number"
}
},
"required": ["messages", "model"]
}
}
}
});
let mut analyzer = SchemaAnalyzer::new(spec).expect("Failed to create analyzer");
let mut analysis = analyzer.analyze().expect("Failed to analyze schema");
// Generate with Specta support enabled
let config = GeneratorConfig {
enable_specta: true,
..Default::default()
};
let generator = CodeGenerator::new(config);
let result = generator
.generate(&mut analysis)
.expect("Failed to generate code");
println!("=== Generated Code with Specta Support ===\n");
println!("{}", result);
}