MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / validateRequiredRecursive

Function validateRequiredRecursive

tests/testSchemas.js:13–32  ·  view source on GitHub ↗
(obj, path = '')

Source from the content-addressed store, hash-verified

11};
12
13const validateRequiredRecursive = (obj, path = '') => {
14 if (!isObject(obj)) return [];
15 let errors = [];
16 if ('properties' in obj && 'required' in obj) {
17 assert.isArray(obj.required);
18 for (const requiredName of obj.required) {
19 if (!obj.properties[requiredName]) {
20 errors.push(`${path && path + '.'}properties.${requiredName}`);
21 }
22 }
23 }
24 for (const property in obj) {
25 const errorsRecursive = validateRequiredRecursive(
26 obj[property],
27 `${path && path + '.'}${property}`
28 );
29 errors = [...errors, ...errorsRecursive];
30 }
31 return errors;
32};
33
34for (const schemaName of Object.keys(schemas)) {
35 describe(`${schemaName} schema`, () => {

Callers 1

validateRequiredFunction · 0.85

Calls 1

isObjectFunction · 0.85

Tested by

no test coverage detected