factory methods: discriminator aliases and missing parent properties - fix - #3524
Conversation
…properties in method factories
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR refactors ChangesoneOf and object payload composition
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested Labels
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@melloware thanks once again 👍 |
Problem
OpenAPI specifications defining polymorphic interfaces often use a combiner (
oneOf/anyOf/allOf) alongside the parent schema's ownproperties.However, Orval's factory generator treated combiners and
propertiesas mutually exclusive.When a combiner was found, the generator returned early and completely ignored the parent's own properties.
Relates to: #3523
Result of the bad code
The generated parent factory simply returned the variant's factory output, which lacked the parent's required properties.
This caused TypeScript compiler errors (e.g., TS2322: Type 'Variant' is not assignable to type 'Variant & { parentProp: string }') when trying to assign the factory output to the generated intersection type.
Example OpenAPI Spec causing the issue
How we fixed it
Refactored
buildPayloadinpackages/core/src/generators/factory.tsto no longer treat combiners andpropertiesas mutually exclusive.The logic now collects payloads from both the combiner and the parent properties into an array, and combines them using
Object.assign({}, ...payloads).This ensures the generated factory correctly outputs an object satisfying the full intersection type, including all required parent and variant properties.
Summary by CodeRabbit
Tests
Refactor