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(rust): add spec compliance analysis for untagged enums
- Added analysis of whether untagged enums violate OpenAPI/JSON Schema spec
- Documented that discriminator is optional ('when used') not required
- Clarified that oneOf MUST validate exactly one match per JSON Schema
- Documented that 'first match wins' violates strict spec compliance
- Added compliance table showing Python as only fully compliant implementation
- Included example of what fully compliant Rust code would look like
Key finding: Current implementations prioritize pragmatism over strict compliance.
Most generators (including Rust) use 'first match wins' which technically
violates the oneOf requirement that exactly one schema must match.
The spec allows validation errors, and strictly speaking, generators should
validate all schemas to ensure exactly one matches for oneOf.
Copy file name to clipboardExpand all lines: docs/rust-oneof-anyof-semantics.md
+68Lines changed: 68 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,74 @@ From the [OpenAPI 3.1.0 Specification](https://spec.openapis.org/oas/v3.1.0#sche
16
16
17
17
These keywords come from [JSON Schema](https://json-schema.org/understanding-json-schema/reference/combining.html) and maintain the same semantics.
18
18
19
+
## Should Untagged Enums Be Allowed? A Spec Analysis
20
+
21
+
### The Discriminator Dilemma
22
+
23
+
The OpenAPI specification states:
24
+
25
+
> "To support polymorphism, the OpenAPI Specification adds the discriminator field. When used, the discriminator will be the name of the property that decides which schema definition validates the structure of the model. As such, the discriminator field MUST be a required field."
26
+
27
+
However, this raises important questions:
28
+
29
+
1.**Is discriminator required for all oneOf schemas?** No, the spec says "when used" - it's optional.
30
+
2.**Does oneOf without discriminator violate the spec?** No, but it may violate the intent.
0 commit comments