Add support for zod/mini generation - #3666
Conversation
|
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 (20)
✅ Files skipped from review due to trivial changes (4)
🚧 Files skipped from review as they are similar to previous changes (14)
📝 WalkthroughWalkthroughAdds a ChangesZod mini variant support
Sequence Diagram(s)sequenceDiagram
participant writeZodSchemas
participant assertZodTarget
participant parseZodValidationSchemaDefinition
participant generateZodSchemaFileContent
participant getZodSchemaImportStatement
writeZodSchemas->>assertZodTarget: validate variant and Zod v4
writeZodSchemas->>parseZodValidationSchemaDefinition: pass zodVariant
writeZodSchemas->>generateZodSchemaFileContent: render schema file content
generateZodSchemaFileContent->>getZodSchemaImportStatement: choose zod import form
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 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 |
There was a problem hiding this comment.
Pull request overview
This PR adds a new Zod output variant (classic vs mini) so Orval can generate schemas targeting the Zod Mini API (zod/mini) and emit the corresponding “functional/check-based” schema expressions, while enforcing that Zod Mini generation only targets Zod v4.
Changes:
- Introduces
override.zod.variant(classic|mini) and normalizes it across Orval options. - Adds Zod target helpers (
getZodImportSource,getZodTypeName,assertZodTarget) and updates schema/code generation + imports to supportzod/mini. - Extends test coverage for Zod Mini rendering, dependency selection, and schema file output.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/zod/src/zod.test.ts | Adds tests for Zod Mini rendering and dependency selection. |
| packages/zod/src/index.ts | Implements Zod Mini rendering path, variant-aware dependencies, and variant propagation through route/schema generation. |
| packages/zod/src/compatible-v4.ts | Adds helpers to validate Mini target (requires v4) and select import/type names by variant. |
| packages/zod/src/compatible-v4.test.ts | Tests new Zod target helper behavior. |
| packages/orval/src/write-zod-specs.ts | Emits variant-aware Zod imports and variant-aware schema type annotations for reusable schemas. |
| packages/orval/src/write-zod-specs.test.ts | Verifies schema files use zod/mini imports and Mini-style output when configured. |
| packages/orval/src/utils/options.ts | Normalizes override.zod.variant and prevents per-operation/tag overrides for it. |
| packages/orval/src/utils/options.test.ts | Tests defaulting/preservation of variant and exclusion from operation/tag overrides. |
| packages/orval/src/reusable-schemas.ts | Threads variant through reusable schema set generation options. |
| packages/mcp/src/index.ts | Updates generated Zod schema file import to be variant-aware (zod vs zod/mini). |
| packages/hono/src/index.ts | Updates generated Zod schema file import to be variant-aware (zod vs zod/mini). |
| packages/core/src/types.ts | Adds ZodVariantOption and documents ZodOptions.variant; includes it in normalized options. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/orval/src/write-zod-specs.ts (1)
906-943: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAdd the missing Zod target assertion in reusable schema writing.
writeZodSchemas()returns intowriteZodSchemasReusable()before its own assertion whengenerateReusableSchemasis enabled. This path resolvesisZodV4and passesvariantthrough, but never rejectsvariant: 'mini'with non-v4 output, so it can emitzod/minicode for an invalid target.Proposed fix
const isZodV4 = resolveIsZodV4( output.override.zod.version, output.packageJson, ); + assertZodTarget({ variant: output.override.zod.variant, isZodV4 }); const strict = output.override.zod.strict.body;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/orval/src/write-zod-specs.ts` around lines 906 - 943, The reusable schema path in writeZodSchemas/writeZodSchemasReusable is missing the Zod target validation, so it can still proceed with variant: 'mini' on non-v4 output. Add the same assertion used in the main Zod writing path before generateReusableSchemaSet is called, using the existing isZodV4 and output.override.zod.variant values to reject invalid mini targets early. Keep the fix in writeZodSchemasReusable so reusable schema generation cannot emit unsupported zod/mini output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/zod/src/index.ts`:
- Around line 1329-1347: The allOf merge logic in the helper generation path is
concatenating each schema’s consts without a separator, which can collapse
adjacent exports into invalid output. Update the loop in the allOf handling
branch to insert a delimiter between each non-empty partSchema.consts chunk
before calling appendConstsChunk, so multiple emitted helpers remain
syntactically separated. Use the allOfArgs iteration and appendConstsChunk path
as the fix point.
- Around line 1432-1449: The tuple rendering in renderMiniDefinition is dropping
helper consts for tuple items and the optional rest schema, so generated
references can point to helpers that were never emitted. Update the tuple branch
in packages/zod/src/index.ts to collect and merge the consts from each item’s
renderMiniDefinition result, and do the same for the next[1] rest schema when
present, before returning the final tuple expression. Keep the logic localized
to the tuple handling path so zod.tuple([...], rest) still renders correctly in
mini mode.
---
Outside diff comments:
In `@packages/orval/src/write-zod-specs.ts`:
- Around line 906-943: The reusable schema path in
writeZodSchemas/writeZodSchemasReusable is missing the Zod target validation, so
it can still proceed with variant: 'mini' on non-v4 output. Add the same
assertion used in the main Zod writing path before generateReusableSchemaSet is
called, using the existing isZodV4 and output.override.zod.variant values to
reject invalid mini targets early. Keep the fix in writeZodSchemasReusable so
reusable schema generation cannot emit unsupported zod/mini output.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f72053ec-523d-4f56-9f54-ae6f77f92b26
📒 Files selected for processing (12)
packages/core/src/types.tspackages/hono/src/index.tspackages/mcp/src/index.tspackages/orval/src/reusable-schemas.tspackages/orval/src/utils/options.test.tspackages/orval/src/utils/options.tspackages/orval/src/write-zod-specs.test.tspackages/orval/src/write-zod-specs.tspackages/zod/src/compatible-v4.test.tspackages/zod/src/compatible-v4.tspackages/zod/src/index.tspackages/zod/src/zod.test.ts
|
@melloware ready for review. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/content/docs/guides/zod.mdx`:
- Around line 101-104: The Zod config example in the docs is internally
inconsistent: the mini variant only supports Zod 4, but the inline comment on
the version setting still implies 3, 4, and auto are all valid for this exact
snippet. Update the example around the zod variant/version settings so the
comment and surrounding text match the Mini-specific behavior in the relevant
docs section, using the override.zod example as the anchor.
- Around line 213-216: The type-inference example in the Zod Mini guide is using
a named type import, which is inconsistent with the Mini namespace style used
elsewhere. Update the snippet to use the namespace type import from zod/mini and
reference inference through zod.infer in the Pet type alias, keeping the example
aligned with the existing Mini import pattern.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 734dea71-dc53-4e3d-8083-967f94cb4c8a
📒 Files selected for processing (13)
docs/content/docs/guides/zod.mdxdocs/content/docs/reference/configuration/output.mdxpackages/angular/src/http-client.test.tspackages/angular/src/http-resource.test.tspackages/core/src/test-utils/context.tspackages/mock/src/faker/getters/combine.test.tspackages/orval/src/reusable-schemas.test.tspackages/orval/src/reusable-schemas.tspackages/orval/src/write-zod-specs.test.tspackages/orval/src/write-zod-specs.tspackages/solid-start/src/index.test.tspackages/zod/src/index.tspackages/zod/src/zod.test.ts
✅ Files skipped from review due to trivial changes (2)
- packages/mock/src/faker/getters/combine.test.ts
- docs/content/docs/reference/configuration/output.mdx
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/orval/src/write-zod-specs.test.ts
- packages/zod/src/index.ts
- packages/orval/src/write-zod-specs.ts
@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: |
anymaniax
left a comment
There was a problem hiding this comment.
Seems really great for me maybe @melloware or @soartec-lab want to check too?
|
agreed this is great. He is fixing the Preview push so he can test it in his actual production code as well! |
This PR introduces zod/mini support so generated zod code is fully tree shakeable.
In large openapi schemas, simply by adding zod generator to the bundle could introduce 1-5Mb of code and more than 200mb of ram simply by importing the generated zod.
Inside cloudflare workers where memory is limited or even on any normal frontend where bundle size matters, this is a LOT.
Zod/mini (so zod is tree shakeable) alongside PURE comments (so generated code is tree shakeable) the final output stops mattering and any bundler can strip it all out during compilation process.
I did not make mini be the default option to not break existing users but I did change some examples around to use the new mini generator since most of the time sdk clients are used in frontends and in almost all occasions lower memory footprint & lower bundle size is great.
docs/content/docs/guides/zod.mdx kindly explains the tree shaking benefits, pls read it as well :)
Summary by CodeRabbit
Summary
New Features
override.zod.variantto generate Zod schemas in classic or mini style (default: classic).Bug Fixes
variantthrough option normalization and reusable/recursive schema generation.Documentation / Tests