Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (manifestContent, callback) {
var schemaFile = path.resolve(__dirname, '..', 'assets', 'web-manifest.json');
var schema = JSON.parse(fs.readFileSync(schemaFile).toString());
var extendedSchemaFile = path.resolve(__dirname, '..', 'assets', 'web-manifest-extended.json');
var extendedSchema = JSON.parse(fs.readFileSync(extendedSchemaFile).toString());
// merge the extended schema with the standard schema
for (var property in extendedSchema.properties) { schema.properties[property] = extendedSchema.properties[property]; }
for (var definition in extendedSchema.definitions) { schema.definitions[definition] = extendedSchema.definitions[definition]; }
var schemaValidation = tv4.validateMultiple(manifestContent, schema, true, true);
var validationResults = [];
schemaValidation.errors.forEach(function (err) {
var message = err.message;
if (err.subErrors) {
message = err.subErrors.reduce(function (previous, current) {
return previous.message + (previous ? ' ' : '') + current.message + '.';
});
}
var member = err.dataPath.split('/').pop();
if (err.code !== tv4.errorCodes.UNKNOWN_PROPERTY || (member && member.indexOf('_') < 0)) {
validationResults.push({
'description': message,
'platform': validationConstants.platforms.all,
'level': (err.code === tv4.errorCodes.UNKNOWN_PROPERTY) ? validationConstants.levels.warning : validationConstants.levels.error,
'member': err.dataPath,
v1: [] as any[],
},
};
if (path.indexOf("assets") !== -1) {
exampleToValidate.assets.v1.push({
[schemaKey]: example,
},
);
} else if (path.indexOf("lifecycle") !== -1) {
exampleToValidate.lifecycle.v1.push({
[schemaKey]: example,
},
);
}
console.log(chalk.blue(yaml.safeDump(exampleToValidate)));
const res = tv4.validateMultiple(exampleToValidate, schema, false, true);
if (!res.valid) {
console.log(util.inspect(exampleToValidate, false, 100, true));
throw new Error(`invalid example ${example} at ${i} ${chalk.green(path)}; Error: at \n${chalk.red(`${res.errors.map((e) => "\t" + e.dataPath + " " + e.message).join("\n")}`)}`);
}
}
}
if (maxDepth === 0) {
return;
}
if (schemaType.items) {
validate(schemaType.items, path + ".items", maxDepth - 1, schema);
}
if (schemaType.properties) {
for (const key of Object.keys(schemaType.properties)) {
validateSchemaV4() {
const result = tv4.validateMultiple(this.data, this.schema);
const validationErrors = result.errors.concat(result.missing);
const amandaCompatibleError = {
length: validationErrors.length,
errorMessages: {}
};
for (let index = 0; index < validationErrors.length; index++) {
const validationError = validationErrors[index];
let error;
if (validationError instanceof Error) {
error = validationError;
} else {
error = new Error('Missing schema');
error.params = { key: validationError };
validate(descriptor) {
const validation = tv4.validateMultiple(descriptor, this._jsonschema);
if (!validation.valid) {
const errors = [];
for (const error of validation.errors) {
errors.push(new Error(`Descriptor validation error:
${error.message}
at "${error.dataPath}" in descriptor and
at "${error.schemaPath}" in profile`));
}
throw errors;
}
return true;
}
exports.validateJSONType = function (schema, value, options) {
var result = tv4.validateMultiple(value, schema, false, _.get(options, 'banUnknownProperties', false));
return result;
};
function validateWithSchema(schema: JsonSchema, message: Message): void {
let result = validateMultiple(message, schema);
if (result.valid) return;
throw new SchemaValidationError(result, message);
}
return { valid: false, errors: [{ message: "Invalid JSON", dataPath: '', subErrors: [], schemaPath: '' }], missingSchemas: [] };
}
if (!schema) {
logError(getErrorMessage("Cannot use a", schema, "schema for validation."));
return { valid: false, errors: [{ message: "Invalid schema", dataPath: '', subErrors: [], schemaPath: '' }], missingSchemas: [] };
}
tv4.addSchema(json);
tv4.addSchema(schema);
await addMissingSchemas(tv4.getMissingUris(), loadSchema);
let result = convertTv4ValidationResult(tv4.validateMultiple(json, schema));
while (result.missingSchemas && result.missingSchemas.length > 0) {
await addMissingSchemas(result.missingSchemas, loadSchema);
result = convertTv4ValidationResult(tv4.validateMultiple(json, schema));
}
return result;
}
validateModelWithSchema(model, schema) {
const result = tv4.validateMultiple(
model,
unnestGroupsInDefinition(schema)
);
if (result == null || result.valid) {
return [];
}
return result.errors.map(error => SchemaFormUtil.parseTV4Error(error));
}
};
function _tv4validation(data, schema) {
if (schema === null) {
return ['Error loading requested profile.']
}
const validation = tv4.validateMultiple(data, schema)
if (validation.valid) {
return true
}
return Utils.errorsToStringArray(validation.errors)
}