mirror of
https://github.com/github/codeql-action.git
synced 2026-10-31 18:09:43 +00:00
Add checkSchema function
This commit is contained in:
30
lib/entry-points.js
generated
30
lib/entry-points.js
generated
@@ -144518,19 +144518,41 @@ function optionalOrNull(validator) {
|
||||
};
|
||||
}
|
||||
function validateSchema(schema, obj) {
|
||||
const result = checkSchema(schema, obj, { failFast: true });
|
||||
return result.valid;
|
||||
}
|
||||
function checkSchema(schema, obj, options = {}, path29 = "") {
|
||||
const result = { valid: true, unknownKeys: [] };
|
||||
const inputKeys = new Set(Object.keys(obj));
|
||||
for (const [key, validator] of Object.entries(schema)) {
|
||||
const hasKey = key in obj;
|
||||
if (validator.required && !hasKey) {
|
||||
return false;
|
||||
result.valid = false;
|
||||
if (options.failFast) {
|
||||
return result;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (validator.required && (obj[key] === void 0 || obj[key] === null)) {
|
||||
return false;
|
||||
result.valid = false;
|
||||
if (options.failFast) {
|
||||
return result;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (hasKey && !validator.validate(obj[key])) {
|
||||
return false;
|
||||
result.valid = false;
|
||||
if (options.failFast) {
|
||||
return result;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
inputKeys.delete(key);
|
||||
}
|
||||
return true;
|
||||
for (const remainingKey of inputKeys) {
|
||||
result.unknownKeys.push(`${path29}${remainingKey}`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// src/util.ts
|
||||
|
||||
Reference in New Issue
Block a user