feat: add exactOptional option for zod and effect generators - #3739
Conversation
Optional object properties emit `.optional()` (zod) / `S.optional()` (effect),
which infer `{ x?: T | undefined }`. Consumers compiling with
exactOptionalPropertyTypes cannot import the generated schemas' inferred types
without a TS2375 mismatch against their exact-optional interfaces.
Add opt-in `override.zod.exactOptional` / `override.effect.exactOptional`
(default false, so existing output is unchanged) that emits, for optional
properties:
- zod v4 classic: `.exactOptional()`
- zod v4 mini: `zod.exactOptional()`
- effect: `S.optionalWith(schema, { exact: true })`
so those consumers infer `{ x?: T }`. zod v3 has no `.exactOptional()`, so the
flag no-ops there. Only `.optional()` is narrowed; `.nullish()` intentionally
admits undefined (legal under exactOptionalPropertyTypes) and is unchanged in
both generators.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (17)
📝 WalkthroughWalkthroughAdds opt-in ChangesExact optional schema generation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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 |
@orval/angular
@orval/axios
@orval/core
@orval/effect
@orval/fetch
@orval/hono
@orval/mcp
@orval/mock
orval
@orval/query
@orval/solid-start
@orval/swr
@orval/zod
commit: |
The exactOptional PR (orval-labs/orval#3739) is merged; add it to the contributions list. Forked repos are excluded from the GitHub search/repositories API by default, so vlasky/sqlite-vec never returned in the counts fetch and stayed "? forks, ? stars". Adding fork:true to the query includes forks alongside non-forks, so it fills like the rest.
Closes #3738.
Optional object properties emit
.optional()(zod) /S.optional()(effect), inferring{ x?: T | undefined }, whichTS2375s against an exact-optional interface underexactOptionalPropertyTypes.Adds an opt-in
override.zod.exactOptional/override.effect.exactOptional(defaultfalse, so existing output is unchanged), mirroringgenerateMeta:.exactOptional(), mini ->zod.exactOptional()S.optionalWith(schema, { exact: true }).exactOptional()does not exist there).optional()is narrowed;.nullish()(which admitsundefined, legal under the flag) is left unchanged in both generatorsThreaded through the reusable-schema / standalone-zod paths so it also applies in
generateReusableSchemasmode. Tests cover classic/mini/v3/nullish, the reusable-schema path, and the normalizer. Default-off output is byte-identical; the full typecheck and the zod/effect/orval package suites pass.Summary by CodeRabbit
New Features
exactOptionalsetting for Zod v4 and Effect schema generation.Documentation