colinhacks/zod · error · Error
dependentSchemas and dependentRequired are not supported
Error message
dependentSchemas and dependentRequired are not supported
What it means
Thrown by convertBaseSchema when the input contains `dependentSchemas` or `dependentRequired`. These conditional-presence keywords have no static Zod representation, so the converter rejects them outright.
Source
Thrown at packages/zod/src/v4/classic/from-json-schema.ts:165
// Handle unsupported features
if (schema.not !== undefined) {
// Special case: { not: {} } represents never
if (typeof schema.not === "object" && Object.keys(schema.not).length === 0) {
return z.never();
}
throw new Error("not is not supported in Zod (except { not: {} } for never)");
}
if (schema.unevaluatedItems !== undefined) {
throw new Error("unevaluatedItems is not supported");
}
if (schema.unevaluatedProperties !== undefined) {
throw new Error("unevaluatedProperties is not supported");
}
if (schema.if !== undefined || schema.then !== undefined || schema.else !== undefined) {
throw new Error("Conditional schemas (if/then/else) are not supported");
}
if (schema.dependentSchemas !== undefined || schema.dependentRequired !== undefined) {
throw new Error("dependentSchemas and dependentRequired are not supported");
}
// Handle $ref
if (schema.$ref) {
const refPath = schema.$ref;
if (ctx.refs.has(refPath)) {
return ctx.refs.get(refPath)!;
}
if (ctx.processing.has(refPath)) {
// Circular reference - use lazy
return z.lazy(() => {
if (!ctx.refs.has(refPath)) {
throw new Error(`Circular reference not resolved: ${refPath}`);
}
return ctx.refs.get(refPath)!;
});
}View on GitHub (pinned to 912f0f51b0)
Solutions
- Replace the dependency with a `.refine()` / `.superRefine()` that enforces the conditional requirement at runtime.
- Model as a discriminated union when the dependency is driven by a tag field.
- Strip the keyword from the input and enforce the rule in application code.
Example fix
// before
{ "type": "object", "dependentRequired": { "creditCard": ["billingAddress"] } }
// after
z.object({
creditCard: z.string().optional(),
billingAddress: z.string().optional(),
}).refine(
(v) => !v.creditCard || v.billingAddress,
{ message: "billingAddress required when creditCard is set", path: ["billingAddress"] }
); Defensive patterns
Strategy: fallback
Validate before calling
function hasDependent(schema: any): boolean {
return schema?.dependentSchemas !== undefined || schema?.dependentRequired !== undefined;
} Prevention
- Model property dependencies in a refine on the converted schema.
- Use discriminated unions when dependencies pivot on a tag field.
- Strip these keywords before conversion and enforce in code.
When it happens
Trigger: Schemas with `dependentRequired: { creditCard: ['billingAddress'] }` or `dependentSchemas: { kind: { ... } }`.
Common situations: Form-validation schemas with inter-field dependencies; OpenAPI extensions; importing schemas written for Ajv.
Related errors
- not is not supported in Zod (except { not: {} } for never)
- unevaluatedItems is not supported
- unevaluatedProperties is not supported
- Conditional schemas (if/then/else) are not supported
- Unsupported type: ${type}
AI-assisted analysis of colinhacks/zod@912f0f51b0 (2026-08-03).
Data as JSON: /data/errors/b3e2b6de5d31a7cc.json.
Report an issue: GitHub.