fix: support of oneOf - #98
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves oneOf/anyOf support by making generated union enums more readable and safer: inline scalar members now get type-based variant names (e.g., String), x-rust-name can name inline union members, and unions that would contain the same lowered Rust type more than once are rejected with a targeted diagnostic.
Changes:
- Add union-variant naming rules (including
x-rust-nameon inline union members and scalar type-based variant names). - Reject
#[serde(untagged)]unions that contain the same lowered Rust type multiple times, with improved console hints. - Extend docs and fixture-based coverage tests for the above behaviors.
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/extensions.md | Documents x-rust-name behavior for inline union members and union variant naming rules. |
| docs/design.md | Adds design rationale around unions and updates x-rust-name guidance. |
| crates/oapi-codegen/tests/generated/recursive_schema.rs | Updates expected generated code for scalar union variant naming. |
| crates/oapi-codegen/tests/generated/oneof_variant_naming.rs | Adds a generated-code snapshot covering the new naming behavior. |
| crates/oapi-codegen/tests/generated.rs | Registers the new generated snapshot module. |
| crates/oapi-codegen/tests/fixtures/unsupported_duplicate_union_variant.yaml | Adds a fixture demonstrating duplicate lowered-type union rejection. |
| crates/oapi-codegen/tests/fixtures/oneof_variant_naming.yaml | Adds a fixture exercising scalar/object/ref/custom union member naming. |
| crates/oapi-codegen/tests/coverage.rs | Adds coverage entries and enables the new fixture-based test. |
| crates/oapi-codegen/src/lower/schema.rs | Implements variant naming tweaks and duplicate-lowered-type detection for unions. |
| crates/oapi-codegen/src/ir.rs | Adds RustType::label() for clearer diagnostics. |
| crates/oapi-codegen/src/console.rs | Adds a dedicated hint for the new “duplicate union type” unsupported-schema diagnostic. |
Suppressed comments (1)
crates/oapi-codegen/src/lower/schema.rs:858
- The doc comment for
extension_stris duplicated; it looks like the new example line was added without removing/updating the old one.
/// Extract a string-valued extension (for example `x-rust-type`) from schema data.
/// Extract a string-valued extension (for example `x-rust-name`) from schema data.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
🎉 This PR is included in version 1.0.0-dev.34 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 1.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
No description provided.