Skip to content

fix(core): handle Zod 4 record, default, and literal types in formatZodType#239

Open
mvanhorn wants to merge 1 commit intovercel-labs:mainfrom
mvanhorn:osc/231-fix-zod4-type-handling
Open

fix(core): handle Zod 4 record, default, and literal types in formatZodType#239
mvanhorn wants to merge 1 commit intovercel-labs:mainfrom
mvanhorn:osc/231-fix-zod4-type-handling

Conversation

@mvanhorn
Copy link

Summary

  • Adds ZodRecord/record case to formatZodType() - returns Record<keyType, valueType> with recursive formatting
  • Adds ZodDefault/default case - unwraps to inner type (e.g., z.boolean().default(false) returns "boolean")
  • Fixes ZodLiteral/literal to support Zod 4's def.values array alongside Zod 3's def.value
  • Applies the same fixes to both @json-render/core and @json-render/yaml packages

Fixes #231

Test plan

  • All 862 existing tests pass
  • Type checking passes (pnpm check-types)

This contribution was developed with AI assistance (Claude Code).

…odType

Add ZodRecord and ZodDefault cases to formatZodType() in both core and
yaml packages. Fix ZodLiteral to support Zod 4's def.values array
in addition to Zod 3's def.value.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 22, 2026

@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestions:

  1. generateExampleValue returns undefined for Zod 4 literal schemas because it reads def.value instead of def.values[0].
  1. exampleValue function returns undefined for Zod 4 literal schemas because it reads def.value instead of def.values[0].

Fix on Vercel

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.

formatZodType doesn't handle Zod 4 record, default, and literal types

1 participant