fix(plugin-zod): wrap nullable allOf members instead of intersecting them#3665
Merged
Conversation
…them A nullable schema inside an `allOf` had its `nullable` keyword merged in as a sibling of the intersection members. The `and` handler treated it as a member, emitting invalid output like `z.lazy(() => nullableStringSchema).and(.nullable())`. Modifier keywords (`nullable`, `nullish`, `optional`, `default`, `describe`) are now lifted out of the `.and()` chain and wrap the whole schema instead, producing `z.lazy(() => nullableStringSchema).nullable()`. Mini mode wraps the result with the functional modifiers. Fixes #3661 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01WUhMV6aMGjVezMYmfzEyQs
🦋 Changeset detectedLatest commit: 36c91ed The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@kubb/adapter-oas
@kubb/ast
@kubb/cli
@kubb/core
kubb
@kubb/mcp
@kubb/oas
@kubb/plugin-client
@kubb/plugin-cypress
@kubb/plugin-faker
@kubb/plugin-mcp
@kubb/plugin-msw
@kubb/plugin-oas
@kubb/plugin-react-query
@kubb/plugin-redoc
@kubb/plugin-solid-query
@kubb/plugin-svelte-query
@kubb/plugin-swr
@kubb/plugin-ts
@kubb/plugin-vue-query
@kubb/plugin-zod
unplugin-kubb
commit: |
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01WUhMV6aMGjVezMYmfzEyQs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #3661 (v4).
A nullable schema inside an
allOfproduced invalid Zod output:The
.and(.nullable())is a syntax error.Why
When a single nullable
allOfmember is merged into the intersection, itsnullablekeyword ends up as a sibling of the real members. Theandhandler inparser.tsonly filtered outoptionalanddescribe, sonullable(andnullish/default) were parsed as intersection members — producing the broken.and(.nullable()).How
Modifier keywords (
nullable,nullish,optional,default,describe) are now separated from the intersection members. The real members build the.and()chain and the modifiers wrap the whole result:Mini mode wraps the result with the functional modifiers (
z.nullable(...)).Tests
packages/plugin-zod/src/generators/nullableAllOf.test.tsxcovering single/multi-memberallOfand mini mode.@kubb/plugin-zodsuite (198) and the3.0.xe2e suite (9) pass; no snapshot churn.🤖 Generated with Claude Code
Generated by Claude Code