4 KeywordErrorDefinition,
7 import type {KeywordCxt} from "../../compile/validate"
8 import {_, not} from "../../compile/codegen"
9 import {alwaysValidSchema} from "../../compile/util"
11 export type PropertyNamesError = ErrorObject<"propertyNames", {propertyName: string}, AnySchema>
13 const error: KeywordErrorDefinition = {
14 message: "property name must be valid",
15 params: ({params}) => _`{propertyName: ${params.propertyName}}`,
18 const def: CodeKeywordDefinition = {
19 keyword: "propertyNames",
21 schemaType: ["object", "boolean"],
23 code(cxt: KeywordCxt) {
24 const {gen, schema, data, it} = cxt
25 if (alwaysValidSchema(it, schema)) return
26 const valid = gen.name("valid")
28 gen.forIn("key", data, (key) => {
29 cxt.setParams({propertyName: key})
32 keyword: "propertyNames",
34 dataTypes: ["string"],
40 gen.if(not(valid), () => {
42 if (!it.allErrors) gen.break()