How to use the ajv.prototype function in ajv

To help you get started, we’ve selected a few ajv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Venryx / DebateMap / Source / Server / Server.ts View on Github external
// if schema is already added, run right away
	if (ajv.getSchema(schemaName)) {
		callback();
		return;
	}
	schemaAddListeners[schemaName] = (schemaAddListeners[schemaName] || []).concat(callback);
}

type AJV_Extended = AJV.Ajv & {
	//AddSchema(schema, name: string): void;
	FullErrorsText(): string;
};
/*AJV.prototype.AddSchema = function(this: AJV_Extended, schema, name: string) {
	return `${this.errorsText()} (${ToJSON(this.errors)})`;
};*/
AJV.prototype.FullErrorsText = function(this: AJV_Extended) {
	return `${this.errorsText()}

Details: ${ToJSON(this.errors, null, 3)}
`;
};

// validation
// ==========

G({Validate}); declare global { function Validate(schemaName: string, data); }
function Validate(schemaName: string, data, removeHelpers = true) {
	if (removeHelpers) {
		let {RemoveHelpers} = require("../Frame/Database/DatabaseHelpers");
		data = RemoveHelpers(Clone(data));
	}
github netlify / build / packages / build / src / plugins / config / json_schema.js View on Github external
const mValidateFromSchema = function(schema, value) {
  const validate = ajv.compile(schema)
  const passed = validate(value)

  if (passed) {
    return
  }

  const [error] = validate.errors
  const errorMessage = Ajv.prototype.errorsText([error], { dataVar: '' }).replace(FIRST_CHAR_REGEXP, '')
  return errorMessage
}