Skip to content

fix(core): leave allOf-wrapped ref discriminator properties untouched - #3998

Merged
melloware merged 1 commit into
orval-labs:masterfrom
ErfanBagheri404:fix/3991-allof-discriminator
Sep 5, 2026
Merged

fix(core): leave allOf-wrapped ref discriminator properties untouched#3998
melloware merged 1 commit into
orval-labs:masterfrom
ErfanBagheri404:fix/3991-allof-discriminator

Conversation

@ErfanBagheri404

@ErfanBagheri404 ErfanBagheri404 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #3991

Summary

When a oneOf discriminator mapping targets a member whose discriminator property is an allOf wrapping a single $ref to a shared enum component (the shape drf-spectacular emits when a member accepts multiple discriminator values), resolveDiscriminators merged the mapping keys into the allOf wrapper itself. The zod generator then rendered the chimera as EventTypeEnum.enum(['Pause', 'Session']).enum on a ZodEnum is its values object, not callable, so the generated code failed with TS2349.

resolveDiscriminators now skips the merge entirely for allOf-wrapped single-$ref properties: the referenced shared schema already carries the full set of valid values, so the property stays exactly as declared.

Output after the fix (from the issue's repro)

export const SessionEventRef = zod.object({
  "id": zod.string(),
  "type": EventTypeEnum
});

Verified end-to-end by running orval on the issue's spec with client: 'zod' and generateReusableSchemas: true.

Notes

A bare $ref discriminator property already took a different (safe) path via the isReference short-circuit; this fix gives the allOf-wrapped variant the same leave-it-alone treatment.

Summary by CodeRabbit

  • Bug Fixes

    • Preserved discriminator properties wrapped in a single reference without adding unintended enum or type values.
    • Improved schema resolution for shared discriminator definitions.
  • Tests

    • Added regression coverage to verify discriminator properties remain unchanged in this scenario.

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 51702289-0efe-40e6-930f-64e4f2495583

📥 Commits

Reviewing files that changed from the base of the PR and between 43dd303 and a62e8af.

📒 Files selected for processing (2)
  • packages/core/src/getters/discriminators.test.ts
  • packages/core/src/getters/discriminators.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

resolveDiscriminators now preserves discriminator properties that wrap one $ref in allOf. A regression test verifies that the property keeps its existing title and structure without injected enum or type values.

Changes

Discriminator preservation

Layer / File(s) Summary
Preserve single-reference discriminator properties
packages/core/src/getters/discriminators.ts, packages/core/src/getters/discriminators.test.ts
The resolver skips mapping-value merging for a discriminator property whose allOf contains one $ref. The test verifies that the referenced shared enum remains unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to a62e8

Discriminator properties that wrap a shared enum reference in a single allOf now remain direct references, preventing invalid generated Zod enum calls while preserving shared schema reuse.

Suggested reviewers: snebjorn

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving discriminator properties that are allOf wrappers around a single $ref.
Linked Issues check ✅ Passed The implementation and regression test address issue #3991. The change prevents enum merging into allOf-wrapped shared references and preserves direct shared-schema reuse.
Out of Scope Changes check ✅ Passed The changes are limited to the discriminator resolution fix and its regression test. They directly support the linked issue objectives, with no unrelated code changes identified.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

@orval/angular

bun add https://pkg.pr.new/@orval/angular@a62e8af

@orval/axios

bun add https://pkg.pr.new/@orval/axios@a62e8af

@orval/core

bun add https://pkg.pr.new/@orval/core@a62e8af

@orval/effect

bun add https://pkg.pr.new/@orval/effect@a62e8af

@orval/fetch

bun add https://pkg.pr.new/@orval/fetch@a62e8af

@orval/hono

bun add https://pkg.pr.new/@orval/hono@a62e8af

@orval/mcp

bun add https://pkg.pr.new/@orval/mcp@a62e8af

@orval/mock

bun add https://pkg.pr.new/@orval/mock@a62e8af

orval

bun add https://pkg.pr.new/orval@a62e8af

@orval/query

bun add https://pkg.pr.new/@orval/query@a62e8af

@orval/solid-start

bun add https://pkg.pr.new/@orval/solid-start@a62e8af

@orval/swr

bun add https://pkg.pr.new/@orval/swr@a62e8af

@orval/zod

bun add https://pkg.pr.new/@orval/zod@a62e8af

commit: a62e8af

@melloware
melloware merged commit e18d1b7 into orval-labs:master Sep 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generateReusableSchemas (zod): discriminator mapping onto a $ref'd enum property emits uncallable SharedEnum.enum([...]) → TS2349

2 participants