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

Method items

src/validator.js:376–412  ·  view source on GitHub ↗
(schema, value, path)

Source from the content-addressed store, hash-verified

374
375 this._validateArraySubSchema = {
376 items (schema, value, path) {
377 const errors = []
378 if (Array.isArray(schema.items)) {
379 for (let i = 0; i < value.length; i++) {
380 /* If this item has a specific schema tied to it */
381 /* Validate against it */
382 if (schema.items[i]) {
383 errors.push(...this._validateSchema(schema.items[i], value[i], `${path}.${i}`))
384 /* If all additional items are allowed */
385 } else if (schema.additionalItems === true) {
386 break
387 /* If additional items is a schema */
388 /* TODO: Incompatibility between version 3 and 4 of the spec */
389 } else if (schema.additionalItems) {
390 errors.push(...this._validateSchema(schema.additionalItems, value[i], `${path}.${i}`))
391 /* If no additional items are allowed */
392 } else if (schema.additionalItems === false) {
393 errors.push({
394 path,
395 property: 'additionalItems',
396 message: this.translate('error_additionalItems', null, schema)
397 })
398 break
399 /* Default for `additionalItems` is an empty schema */
400 } else {
401 break
402 }
403 }
404 /* `items` is a schema */
405 } else {
406 /* Each item in the array must validate against the schema */
407 value.forEach((e, i) => {
408 errors.push(...this._validateSchema(schema.items, e, `${path}.${i}`))
409 })
410 }
411 return errors
412 },
413 maxItems (schema, value, path) {
414 if (value.length > schema.maxItems) {
415 return [{

Callers 3

mergeEvaluatedMethod · 0.80
validateTupleFunction · 0.80
addEvaluatedFromFunction · 0.80

Calls 1

_validateSchemaMethod · 0.95

Tested by

no test coverage detected