| 80 | const schemaCache = new Map(); |
| 81 | |
| 82 | async function loadAndCompileSchema(schemaPath) { |
| 83 | // Use cache to avoid "already exists" error |
| 84 | if (schemaCache.has(schemaPath)) { |
| 85 | return schemaCache.get(schemaPath); |
| 86 | } |
| 87 | |
| 88 | const schemaContent = fs.readFileSync(schemaPath, 'utf8'); |
| 89 | const schema = JSON.parse(schemaContent); |
| 90 | const validate = await ajv.compileAsync(schema); |
| 91 | |
| 92 | schemaCache.set(schemaPath, validate); |
| 93 | return validate; |
| 94 | } |
| 95 | |
| 96 | // Schemas that should have ext field |
| 97 | const EXTENSIBLE_SCHEMAS = [ |