-
Notifications
You must be signed in to change notification settings - Fork 0
fix(api): safeextend when attaching variable schemas #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| import { | ||||||
| extend, | ||||||
| type output, | ||||||
| pipe, | ||||||
| safeExtend, | ||||||
| transform, | ||||||
| type ZodMiniAny, | ||||||
| ZodMiniObject, | ||||||
|
|
@@ -77,15 +77,15 @@ function objectVariableResolverParser< | |||||
| const $objectParser = objectParser instanceof ZodMiniObject | ||||||
| ? objectEntries(objectParser._zod.def.shape).reduce<ZodMiniObject>( | ||||||
| (acc, [key, parser]) => | ||||||
| extend(acc, { | ||||||
| safeExtend(acc, { | ||||||
| [key]: attachVariableResolver(variablesRegistry, parser), | ||||||
| }), | ||||||
| objectParser, | ||||||
| ) | ||||||
| : objectEntries(objectParser._zod.def.shape).reduce<ZodObject>( | ||||||
| (acc, [key, parser]) => | ||||||
| acc.extend({ | ||||||
| [key]: attachVariableResolver(variablesRegistry, parser), | ||||||
| acc.safeExtend({ | ||||||
| [key]: attachVariableResolver(variablesRegistry, parser) as any, | ||||||
|
||||||
| [key]: attachVariableResolver(variablesRegistry, parser) as any, | |
| [key]: attachVariableResolver(variablesRegistry, parser) as $ZodType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is meant to fix extending object schemas that include refinements, but current tests only cover
.refine()on a primitive (z.string().refine(...)) and don't exerciseobjectVariableResolverParseron a refined object schema (e.g.,z.object({...}).refine(...)orsuperRefine). Please add a regression test that callsData.create().usePayload(...)with a refined object payload and uses variables within nested properties, ensuringaddRules()no longer throws during schema attachment.