MCPcopy Create free account
hub / github.com/json-editor/json-editor / validateTuple

Function validateTuple

docs/scripts/ajv-validator.js:5001–5028  ·  view source on GitHub ↗
(cxt, extraItems, schArr = cxt.schema)

Source from the content-addressed store, hash-verified

4999 },
5000 };
5001 function validateTuple(cxt, extraItems, schArr = cxt.schema) {
5002 const { gen, parentSchema, data, keyword, it } = cxt;
5003 checkStrictTuple(parentSchema);
5004 if (it.opts.unevaluated && schArr.length && it.items !== true) {
5005 it.items = util_1.mergeEvaluated.items(gen, schArr.length, it.items);
5006 }
5007 const valid = gen.name("valid");
5008 const len = gen.const("len", (0, codegen_1._) `${data}.length`);
5009 schArr.forEach((sch, i) => {
5010 if ((0, util_1.alwaysValidSchema)(it, sch))
5011 return;
5012 gen.if((0, codegen_1._) `${len} > ${i}`, () => cxt.subschema({
5013 keyword,
5014 schemaProp: i,
5015 dataProp: i,
5016 }, valid));
5017 cxt.ok(valid);
5018 });
5019 function checkStrictTuple(sch) {
5020 const { opts, errSchemaPath } = it;
5021 const l = schArr.length;
5022 const fullTuple = l === sch.minItems && (l === sch.maxItems || sch[extraItems] === false);
5023 if (opts.strictTuples && !fullTuple) {
5024 const msg = `"${keyword}" is ${l}-tuple, but minItems or maxItems/${extraItems} are not specified or different at path "${errSchemaPath}"`;
5025 (0, util_1.checkStrictMode)(it, msg, opts.strictTuples);
5026 }
5027 }
5028 }
5029 exports.validateTuple = validateTuple;
5030 exports.default = def;
5031//# sourceMappingURL=items.js.map

Callers 1

codeFunction · 0.85

Calls 7

checkStrictTupleFunction · 0.85
itemsMethod · 0.80
subschemaMethod · 0.80
okMethod · 0.80
nameMethod · 0.45
constMethod · 0.45
ifMethod · 0.45

Tested by

no test coverage detected