diff --git a/lib/vocabularies/jtd/properties.ts b/lib/vocabularies/jtd/properties.ts index 1ef172b5d..b51256d60 100644 --- a/lib/vocabularies/jtd/properties.ts +++ b/lib/vocabularies/jtd/properties.ts @@ -2,7 +2,7 @@ import type {CodeKeywordDefinition} from "../../types" import type KeywordCxt from "../../compile/context" import {propertyInData, allSchemaProperties, isOwnProperty} from "../code" import {alwaysValidSchema, schemaRefOrVal} from "../../compile/util" -import {_, and, Code, Name} from "../../compile/codegen" +import {_, and, not, Code, Name} from "../../compile/codegen" import {checkMetadata} from "./metadata" import {checkNullableObject} from "./nullable" @@ -116,7 +116,7 @@ export function validateProperties(cxt: KeywordCxt): void { if (props.length > 8) { // TODO maybe an option instead of hard-coded 8? const propsSchema = schemaRefOrVal(it, parentSchema[keyword], keyword) - additional = isOwnProperty(gen, propsSchema as Code, key) + additional = not(isOwnProperty(gen, propsSchema as Code, key)) } else if (props.length) { additional = and(...props.map((p) => _`${key} !== ${p}`)) } else { diff --git a/spec/issues/1501_jtd_many_properties.spec.ts b/spec/issues/1501_jtd_many_properties.spec.ts new file mode 100644 index 000000000..20e24b76e --- /dev/null +++ b/spec/issues/1501_jtd_many_properties.spec.ts @@ -0,0 +1,27 @@ +import type Ajv from "../.." +import _Ajv from "../ajv_jtd" +import * as assert from "assert" + +const PROP_COUNT = 10 + +describe("schema with many properties", () => { + let ajv: Ajv + const schema = {properties: {}} + const data = {} + const invalidData = {} + + before(() => { + ajv = new _Ajv() + for (let i = 0; i < PROP_COUNT; i++) { + const prop = `prop${i}` + schema.properties[prop] = {type: "uint16"} + data[prop] = i + invalidData[prop] = -i + } + }) + + it("should correctly compile reference to schema", () => { + assert.strictEqual(ajv.validate(schema, data), true) + assert.strictEqual(ajv.validate(schema, invalidData), false) + }) +})