{"record":{"id":"b3e2b6de5d31a7cc","repo":"colinhacks/zod","slug":"dependentschemas-and-dependentrequired-are-not-sup","errorCode":null,"errorMessage":"dependentSchemas and dependentRequired are not supported","messagePattern":"dependentSchemas and dependentRequired are not supported","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/zod/src/v4/classic/from-json-schema.ts","lineNumber":166,"sourceCode":"  // Handle unsupported features\n  if (schema.not !== undefined) {\n    // Special case: { not: {} } represents never\n    if (typeof schema.not === \"object\" && Object.keys(schema.not).length === 0) {\n      return z.never();\n    }\n    throw new Error(\"not is not supported in Zod (except { not: {} } for never)\");\n  }\n  if (schema.unevaluatedItems !== undefined) {\n    throw new Error(\"unevaluatedItems is not supported\");\n  }\n  if (schema.unevaluatedProperties !== undefined) {\n    throw new Error(\"unevaluatedProperties is not supported\");\n  }\n  if (schema.if !== undefined || schema.then !== undefined || schema.else !== undefined) {\n    throw new Error(\"Conditional schemas (if/then/else) are not supported\");\n  }\n  if (schema.dependentSchemas !== undefined || schema.dependentRequired !== undefined) {\n    throw new Error(\"dependentSchemas and dependentRequired are not supported\");\n  }\n\n  // Handle $ref\n  if (schema.$ref) {\n    const refPath = schema.$ref;\n    if (ctx.refs.has(refPath)) {\n      return ctx.refs.get(refPath)!;\n    }\n\n    if (ctx.processing.has(refPath)) {\n      // Circular reference - use lazy\n      return z.lazy(() => {\n        if (!ctx.refs.has(refPath)) {\n          throw new Error(`Circular reference not resolved: ${refPath}`);\n        }\n        return ctx.refs.get(refPath)!;\n      });\n    }","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/colinhacks/zod/blob/2d90846af918af9602e088812d63a035d47cdbe4/packages/zod/src/v4/classic/from-json-schema.ts#L148-L184","documentation":"Thrown by convertBaseSchema (packages/zod/src/v4/classic/from-json-schema.ts:166) when the source JSON Schema uses `dependentSchemas` or `dependentRequired` (draft-2019+ keywords that make property requirements conditional on the presence of other properties). Zod has no native combinator for 'if this key is present then require those keys', so the converter rejects the document.","triggerScenarios":"Calling fromJSONSchema on a schema containing `dependentRequired: { creditCard: ['billingAddress'] }` or `dependentSchemas: { foo: { required: ['bar'] } }`. The presence of either key triggers the throw.","commonSituations":"Real-world form schemas (e.g. require billingAddress when creditCard is set); draft-2019+ documents that formalised the older draft-7 'dependencies' keyword into these two; OpenAPI 3.1 schemas that adopt the 2019-09 vocabulary; strict enterprise schemas.","solutions":["Express the dependency as a post-conversion .superRefine() that checks the conditional and pushes an issue on the dependent path.","Rewrite as a z.discriminatedUnion or z.union where each branch is a self-contained object schema representing one valid combination.","Remove the dependent* keys if they encode optional business rules you can enforce outside the schema.","Pre-process to translate dependentRequired into explicit union branches before conversion."],"exampleFix":"// before\nconst schema = {\n  type: 'object',\n  properties: { creditCard: { type: 'string' }, billingAddress: { type: 'string' } },\n  dependentRequired: { creditCard: ['billingAddress'] },\n};\nfromJSONSchema(schema); // throws\n\n// after — enforce the dependency with a refinement\nconst schema = z\n  .object({\n    creditCard: z.string().optional(),\n    billingAddress: z.string().optional(),\n  })\n  .superRefine((v, ctx) => {\n    if (v.creditCard && !v.billingAddress) {\n      ctx.addIssue({\n        code: 'custom',\n        path: ['billingAddress'],\n        message: 'billingAddress is required when creditCard is set',\n      });\n    }\n  });","handlingStrategy":"validation","validationCode":"function assertNoDependent(root: unknown) {\n  const visit = (node: unknown): void => {\n    if (Array.isArray(node)) return node.forEach(visit);\n    if (!node || typeof node !== 'object') return;\n    const o = node as Record<string, unknown>;\n    if ('dependentSchemas' in o || 'dependentRequired' in o) {\n      throw new Error('Schema uses dependentSchemas/dependentRequired, which Zod cannot express directly');\n    }\n    for (const v of Object.values(o)) visit(v);\n  };\n  visit(root);\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Express property dependencies as a .superRefine() that pushes issues on the dependent path.","Rewrite dependentRequired as explicit z.union branches, one per valid property combination.","Strip dependent* keywords from draft-2019+ documents before conversion.","For form-validation rules, model them in the UI layer instead of in the JSON Schema."],"tags":["json-schema","from-json-schema","conversion","unsupported","dependencies"],"backgroundTag":null,"analyzedSha":"2d90846af918af9602e088812d63a035d47cdbe4","analyzedAt":"2026-08-11T01:21:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}