You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add informal findings about wing328's test case
Documented the real-world implications of the anyOf fix by showing:
- How the old generator would produce duplicate enum variants (broken Rust code)
- Why wing328's test case perfectly demonstrates the problem
- The practical difference between treating anyOf as choice vs composition
These findings emerged from merging PR OpenAPITools#21911 and seeing firsthand how
the old behavior would literally generate uncompilable code for certain
anyOf schemas.
This is what happens when you treat anyOf (composition) as oneOf (choice) - you get nonsensical code. The correct approach generates a struct where both can coexist.
String(String), // Second string option - DUPLICATE! This is broken!
434
+
}
435
+
```
436
+
437
+
See the problem? We'd have duplicate enum variants! The generator would actually produce invalid Rust code. Plus, even if it worked, you could only choose ONE option, not both.
pub as_any_of_1: Option<String>, // Known enum values
450
+
}
451
+
```
452
+
453
+
Now both fields can be set! This is actually useful - imagine an API that accepts both a freeform model name AND validates against known models. With anyOf, you can validate against both schemas simultaneously.
454
+
455
+
### Another Example from Wing328's Tests
456
+
He also included this more complex anyOf:
457
+
```yaml
458
+
AnotherAnyOfTest:
459
+
anyOf:
460
+
- type: string
461
+
- type: integer
462
+
- type: array
463
+
items:
464
+
type: string
465
+
```
466
+
467
+
Old behavior would force you to choose: "Is this a string OR an integer OR an array?"
468
+
469
+
New behavior lets you have all three! Maybe it's a weird API, but that's what anyOf means - the data can match multiple schemas at once. The generator shouldn't make assumptions about what's "sensible" - it should implement the spec correctly.
0 commit comments