|
1 | | -import type { $ZodType } from "@zod/core"; |
| 1 | +import type { $ZodObject, $ZodTransform, $ZodType } from "@zod/core"; |
2 | 2 | import { Request } from "express"; |
3 | 3 | import * as R from "ramda"; |
4 | 4 | import { globalRegistry, z } from "zod"; |
@@ -86,11 +86,10 @@ export const getMessageFromError = (error: Error): string => { |
86 | 86 | }; |
87 | 87 |
|
88 | 88 | /** Takes the original unvalidated examples from the properties of ZodObject schema shape */ |
89 | | -export const pullExampleProps = <T extends z.ZodObject>(subject: T) => |
90 | | - Object.entries(subject.shape).reduce<Partial<z.input<T>>[]>( |
| 89 | +export const pullExampleProps = <T extends $ZodObject>(subject: T) => |
| 90 | + Object.entries(subject._zod.def.shape).reduce<Partial<z.input<T>>[]>( |
91 | 91 | (acc, [key, schema]) => { |
92 | | - const examples = |
93 | | - (schema as z.ZodType).meta()?.[metaSymbol]?.examples || []; |
| 92 | + const { examples = [] } = globalRegistry.get(schema)?.[metaSymbol] || {}; |
94 | 93 | return combinations(acc, examples.map(R.objOf(key)), ([left, right]) => ({ |
95 | 94 | ...left, |
96 | 95 | ...right, |
@@ -160,8 +159,8 @@ export const makeCleanId = (...args: string[]) => { |
160 | 159 | }; |
161 | 160 |
|
162 | 161 | export const getTransformedType = R.tryCatch( |
163 | | - <T>(schema: z.ZodTransform<unknown, T>, sample: T) => |
164 | | - typeof schema.parse(sample), |
| 162 | + <T>(schema: $ZodTransform<unknown, T>, sample: T) => |
| 163 | + typeof z.parse(schema, sample), |
165 | 164 | R.always(undefined), |
166 | 165 | ); |
167 | 166 |
|
|
0 commit comments