{"record":{"id":"97c43d7910f17f68","repo":"JuliusBrussee/caveman","slug":"file-unsupported-or-missing-schema","errorCode":null,"errorMessage":"${file}: unsupported or missing $schema","messagePattern":"(.+?): unsupported or missing \\$schema","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-schemas.mjs","lineNumber":20,"sourceCode":"import { fileURLToPath } from \"node:url\";\nimport path from \"node:path\";\nimport Ajv2020 from \"ajv/dist/2020.js\";\n\nconst packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), \"..\");\nconst schemaRoot = path.join(packageRoot, \"schemas\");\nconst files = (await readdir(schemaRoot))\n  .filter((name) => name.endsWith(\".schema.json\"))\n  .sort();\n\nif (files.length === 0) {\n  throw new Error(\"no JSON schemas found\");\n}\n\nconst schemas = [];\nfor (const file of files) {\n  const schema = JSON.parse(await readFile(path.join(schemaRoot, file), \"utf8\"));\n  if (schema.$schema !== \"https://json-schema.org/draft/2020-12/schema\") {\n    throw new Error(`${file}: unsupported or missing $schema`);\n  }\n  if (typeof schema.$id !== \"string\" || schema.$id.length === 0) {\n    throw new Error(`${file}: missing $id`);\n  }\n  schemas.push(schema);\n}\n\nconst ajv = new Ajv2020({ allErrors: true, strict: true });\najv.addSchema(schemas);\nfor (const schema of schemas) {\n  const validate = ajv.getSchema(schema.$id);\n  if (!validate) throw new Error(`schema failed to compile: ${schema.$id}`);\n}\n\nconst agentFixtureRoot = path.join(packageRoot, \"fixtures\", \"agent\");\nconst fixtureFiles = (await readdir(agentFixtureRoot))\n  .filter((name) => name.endsWith(\".json\"))\n  .sort();","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-schemas.mjs#L2-L38","documentation":"Every schema file must declare $schema as exactly the JSON Schema 2020-12 meta-schema URI, because the script compiles schemas with Ajv2020. A schema with a missing $schema, an older draft (draft-07, 2019-09), or a typo'd URI makes the file unsupported and throws this error naming the offending file.","triggerScenarios":"Running scripts/validate-schemas.mjs when a file in schemas/*.schema.json has schema.$schema !== \"https://json-schema.org/draft/2020-12/schema\" — typically a draft-07 schema copied from another project or a missing top-level $schema key.","commonSituations":"Copy-pasting a schema from a project using draft-07 and ajv (not Ajv2020); a schema authoring tool emitting an older meta-schema; hand-written schemas omitting $schema entirely.","solutions":["Set \"$schema\": \"https://json-schema.org/draft/2020-12/schema\" at the top level of the named schema file","If the schema uses draft-07 features, port it to 2020-12 instead of downgrading the script's Ajv","Check for trailing whitespace/typos in the $schema URI string","Regenerate the schema from the contract toolchain configured for 2020-12"],"exampleFix":"// before\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"$id\": \"https://caveman.so/schemas/adapter-conformance.schema.json\"\n}\n// after\n{\n  \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n  \"$id\": \"https://caveman.so/schemas/adapter-conformance.schema.json\"\n}","handlingStrategy":"validation","validationCode":"const REQUIRED = 'https://json-schema.org/draft/2020-12/schema';\nfor (const f of files) {\n  const s = JSON.parse(await readFile(path.join(schemaRoot, f), 'utf8'));\n  if (s.$schema !== REQUIRED) throw new Error(`${f}: $schema must be ${REQUIRED}`);\n}","typeGuard":"const isDraft2020 = (s) => typeof s?.$schema === 'string' && s.$schema === 'https://json-schema.org/draft/2020-12/schema';","tryCatchPattern":"try { loadSchemas(); } catch (e) { if (e.message.includes('unsupported or missing $schema')) { console.error('Port schema to draft 2020-12:', e.message); process.exitCode = 1; } else throw e; }","preventionTips":["Copy schemas only from 2020-12-based projects or port them on import","Add a pre-commit hook that checks $schema in every schema file","Use an editor schema template with the meta-schema prefilled"],"tags":["json-schema","ajv","schemas"],"backgroundTag":"unsupported-config-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}