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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#![recursion_limit = "512"]
use openapi_to_rust::{CodeGenerator, GeneratorConfig, SchemaAnalyzer};
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🔥 Running EXTREME stress test...\n");
// The most complex schema I can think of - combining ALL edge cases
let spec = json!({
"openapi": "3.1.0",
"info": {
"title": "Extreme Stress Test API",
"version": "1.0.0"
},
"components": {
"schemas": {
"MegaComplexSchema": {
"$recursiveAnchor": true,
"type": "object",
"properties": {
// Edge case field names
"type": {"type": "string", "enum": ["mega"], "default": "mega"},
"match": {"type": "integer", "default": 42},
"fn": {"type": "boolean", "default": true},
"123field": {"type": "string", "default": "numeric"},
"kebab-case-field": {"type": "string"},
"snake_case_field": {"type": "string"},
"camelCaseField": {"type": "string"},
"PascalCaseField": {"type": "string"},
"with.dots.everywhere": {"type": "string"},
"with spaces in name": {"type": "string"},
"with@#$%symbols": {"type": "string"},
"🚀unicode-field": {"type": "string"},
// Complex nullable patterns
"nullable_complex": {
"anyOf": [
{
"type": "object",
"properties": {
"nested": {
"anyOf": [
{"$recursiveRef": "#"},
{"type": "null"}
]
}
}
},
{"type": "null"}
]
},
// Deeply nested arrays with recursion
"mega_nested_array": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"anyOf": [
{"$recursiveRef": "#"},
{"type": "string"},
{"type": "null"}
]
}
}
},
"default": []
},
// Complex discriminated union with allOf
"mega_union": {
"oneOf": [
{
"allOf": [
{"$ref": "#/components/schemas/BaseType"},
{
"type": "object",
"properties": {
"union_type": {"type": "string", "enum": ["variant_a"]},
"a_specific": {
"anyOf": [
{"type": "string"},
{"type": "integer"},
{"$recursiveRef": "#"}
]
}
},
"required": ["union_type"]
}
]
},
{
"allOf": [
{"$ref": "#/components/schemas/BaseType"},
{
"type": "object",
"properties": {
"union_type": {"type": "string", "enum": ["variant_b"]},
"b_specific": {
"type": "array",
"items": {"$recursiveRef": "#"}
}
},
"required": ["union_type"]
}
]
}
],
"discriminator": {"propertyName": "union_type"}
},
// Extreme composition
"composition_madness": {
"allOf": [
{"$ref": "#/components/schemas/BaseType"},
{"$ref": "#/components/schemas/Timestamped"},
{"$ref": "#/components/schemas/WithMetadata"},
{
"type": "object",
"properties": {
"final_field": {
"oneOf": [
{"type": "string"},
{"type": "integer"},
{
"type": "object",
"additionalProperties": {
"anyOf": [
{"$recursiveRef": "#"},
{"type": "string"}
]
}
}
]
}
}
}
]
}
},
"required": ["type", "match", "fn"],
"additionalProperties": {
"anyOf": [
{"$recursiveRef": "#"},
{"type": "string"},
{"type": "integer"},
{"type": "boolean"},
{"type": "null"}
]
}
},
"BaseType": {
"type": "object",
"properties": {
"id": {"type": "string"},
"base_field": {"type": "string", "default": "base"}
},
"required": ["id"]
},
"Timestamped": {
"type": "object",
"properties": {
"created_at": {"type": "string", "format": "date-time"},
"updated_at": {"type": "string", "format": "date-time", "nullable": true}
}
},
"WithMetadata": {
"type": "object",
"properties": {
"metadata": {
"type": "object",
"additionalProperties": true,
"properties": {
"version": {"type": "integer", "default": 1},
"tags": {
"type": "array",
"items": {"type": "string"},
"default": []
}
}
}
}
},
"ExtremeEnum": {
"type": "string",
"enum": [
"normal",
"123",
"null",
"true",
"false",
"with spaces",
"with.dots",
"type",
"match",
"fn",
"impl"
],
"default": "normal"
},
"CircularReference": {
"type": "object",
"properties": {
"id": {"type": "string"},
"parent": {"$ref": "#/components/schemas/CircularReference"},
"children": {
"type": "array",
"items": {"$ref": "#/components/schemas/CircularReference"}
},
"sibling": {"$ref": "#/components/schemas/CircularSibling"}
},
"required": ["id"]
},
"CircularSibling": {
"type": "object",
"properties": {
"id": {"type": "string"},
"reference_back": {"$ref": "#/components/schemas/CircularReference"},
"other_sibling": {"$ref": "#/components/schemas/CircularSibling"}
},
"required": ["id"]
}
}
}
});
println!("🔍 Analyzing extreme schema...");
let mut analyzer = SchemaAnalyzer::new(spec)?;
let mut analysis = analyzer.analyze()?;
println!(
" ✅ {} schemas analyzed successfully",
analysis.schemas.len()
);
println!(
" 📊 Dependency graph has {} edges",
analysis.dependencies.edges.len()
);
println!(
" 🔄 {} recursive schemas detected",
analysis.dependencies.recursive_schemas.len()
);
println!("\n🛠️ Generating code...");
let config = GeneratorConfig {
module_name: "extreme_api".to_string(),
..Default::default()
};
let generator = CodeGenerator::new(config);
let generated_code = generator.generate(&mut analysis)?;
let line_count = generated_code.lines().count();
let char_count = generated_code.len();
println!(" ✅ Code generation completed:");
println!(" 📄 {line_count} lines generated");
println!(" 🔤 {char_count} characters generated");
// Basic sanity checks
assert!(generated_code.contains("pub mod extreme_api"));
assert!(generated_code.contains("use serde"));
assert!(generated_code.contains("pub struct MegaComplexSchema"));
assert!(generated_code.contains("pub enum ExtremeEnum"));
// Check that problematic identifiers were sanitized
assert!(generated_code.contains("field_123field")); // Number prefix handled
assert!(generated_code.contains("type_")); // Reserved keyword handled
assert!(generated_code.contains("match_")); // Reserved keyword handled
assert!(generated_code.contains("fn_")); // Reserved keyword handled
// Check that Box wrapping is applied for recursive types
assert!(generated_code.contains("Box<"));
println!("\n🎯 Extreme stress test results:");
println!(" ✅ All edge cases handled successfully");
println!(" ✅ Complex recursive patterns supported");
println!(" ✅ Identifier sanitization working");
println!(" ✅ Generated code passes basic validation");
println!("\n🚀 EXTREME STRESS TEST PASSED! 🚀");
Ok(())
}