1 import {KeywordCxt} from "../../ajv"
2 import type {CodeKeywordDefinition} from "../../types"
3 import {alwaysValidSchema} from "../../compile/util"
5 const def: CodeKeywordDefinition = {
8 code(cxt: KeywordCxt) {
10 const {gen, schema, it} = cxt
11 if (alwaysValidSchema(it, schema)) return
12 const valid = gen.name("valid")
13 cxt.subschema({keyword: "metadata", jtdMetadata: true}, valid)
18 export function checkMetadata({it, keyword}: KeywordCxt, metadata?: boolean): void {
19 if (it.jtdMetadata !== metadata) {
20 throw new Error(`JTD: "${keyword}" cannot be used in this schema location`)