* Check if schema is optional
(schema: z.ZodTypeAny)
| 187 | * Check if schema is optional |
| 188 | */ |
| 189 | function isOptional(schema: z.ZodTypeAny): boolean { |
| 190 | let current = schema; |
| 191 | |
| 192 | while (true) { |
| 193 | const def = (current as any)._def as ZodDef | undefined; |
| 194 | |
| 195 | if (!def) break; |
| 196 | |
| 197 | const typeName = getDefType(def); |
| 198 | |
| 199 | if (typeName === 'optional') { |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | if (typeName === 'default' || typeName === 'nullable') { |
| 204 | current = def.innerType; |
| 205 | continue; |
| 206 | } |
| 207 | |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | return false; |
| 212 | } |
no test coverage detected