{"record":{"id":"7caf4a0cd7875ebe","repo":"hapijs/joi","slug":"unsupported-json-schema-target-options-target","errorCode":null,"errorMessage":"Unsupported JSON Schema target: ${options.target}","messagePattern":"Unsupported JSON Schema target: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/base.js","lineNumber":75,"sourceCode":"            ruleset: null,                          // null: use last, false: error, number: start position\n            whens: {}                               // Runtime cache of generated whens\n        };\n    }\n\n    // Manifest\n\n    describe() {\n\n        assert(typeof Manifest.describe === 'function', 'Manifest functionality disabled');\n        return Manifest.describe(this);\n    }\n\n    $_jsonSchema(mode, options = {}) {\n\n        if (options.target !== undefined &&\n            options.target !== internals.jsonSchemaTarget) {\n\n            throw new Error(`Unsupported JSON Schema target: ${options.target}`);\n        }\n\n        const rootCall = !options.$defs;\n        const defs = options.$defs ?? {};\n\n        let schema = {};\n\n        const isTypeAny = this.type === 'any';\n        const isOnly = this._flags.only;\n\n        const valids = this._valids && Array.from(this._valids._values).filter((v) => v !== null);\n        let typesOverlap = true;\n\n        // If 'only' is set, check if the allowed values' types overlap with the schema type\n\n        if (valids && valids.length && isOnly && !isTypeAny) {\n            const types = new Set(valids.map((v) => typeof v));\n            typesOverlap = types.has(this.type) || (this.type === 'date' && types.has('object'));","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/hapijs/joi/blob/58ce83e919a14f481f1a1edf30ee212cf90ba6a4/lib/base.js#L57-L93","documentation":"joi's $_jsonSchema() serializes a schema to JSON Schema (draft 2020-12). The library only supports the JSON Schema target it was built against (internals.jsonSchemaTarget), so passing any other target string throws this error at lib/base.js:75. It is a fail-fast guard because joi cannot guarantee correct output for other draft versions.","triggerScenarios":"Calling schema.$_jsonSchema({ target: 'draft-07' }) or any target other than '2020-12' (e.g. 'draft-4', 'openapi-3.0'); also occurs when using $standard/standard-schema integration (~standard) with options.target set by tooling to an unsupported draft.","commonSituations":"Copy-pasting JSON Schema export options from another library's docs; upgrading/downgrading joi so the supported draft no longer matches a hardcoded target in build scripts or OpenAPI generators; configuring a validator plugin (e.g. standard-schema consumers) with an explicit target.","solutions":["Remove the options.target property entirely and let joi use its built-in default target (internals.jsonSchemaTarget, currently '2020-12').","Set target to the version joi supports — check the value documented for your installed joi version (npm ls joi, then the docs) and use that exact string, e.g. { target: '2020-12' }.","If you need a different draft, generate with joi's supported target and convert the output with a converter tool instead of asking joi for it.","Upgrade or downgrade joi to a version whose JSON Schema target matches the one your toolchain requires."],"exampleFix":"// before\nconst jsonSchema = schema.$_jsonSchema({ target: 'draft-07' });\n// after\nconst jsonSchema = schema.$_jsonSchema(); // uses joi's supported target (2020-12)","handlingStrategy":"validation","validationCode":"const SUPPORTED_TARGET = '2020-12'; // check docs for your joi version\nif (options?.target !== undefined && options.target !== SUPPORTED_TARGET) {\n  throw new TypeError(`target must be omitted or '${SUPPORTED_TARGET}', got: ${options.target}`);\n}\nconst jsonSchema = schema.$_jsonSchema(options);","typeGuard":"function hasValidTarget(options) {\n  const SUPPORTED = '2020-12';\n  return !options || options.target === undefined || options.target === SUPPORTED;\n}","tryCatchPattern":"let jsonSchema;\ntry {\n  jsonSchema = schema.$_jsonSchema(options);\n} catch (err) {\n  if (err.message.startsWith('Unsupported JSON Schema target')) {\n    jsonSchema = schema.$_jsonSchema(); // fall back to default target\n  } else {\n    throw err;\n  }\n}","preventionTips":["Omit options.target unless you specifically need it — the default is always supported.","Pin your joi version in package.json so the supported target doesn't change under you.","Centralize JSON Schema export in one helper that owns the target constant.","When integrating with standard-schema tooling, verify which draft the tool expects before passing its target through."],"tags":["json-schema","configuration","validation"],"backgroundTag":"unsupported-json-schema-target","analyzedSha":"58ce83e919a14f481f1a1edf30ee212cf90ba6a4","analyzedAt":"2026-09-01T18:09:30.061Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}