How to use the addSchema function from tv4

Find comprehensive JavaScript tv4.addSchema code examples handpicked from public code repositorys.

48
49
50
51
52
53
54
55
56
57
 */
const getImplicitLegacySchemaVersion = (jsonSchema) => {
  const [schemaVersion] = [['draftV4', metaSchemaV4]].find(
    ([_, metaSchema]) => {
      tv4.reset();
      tv4.addSchema('', metaSchema);
      tv4.addSchema(metaSchema.$schema, metaSchema);
      const validationResult = tv4.validateResult(jsonSchema, metaSchema);
      return validationResult.valid;
    }
fork icon22
star icon94
watch icon16

+ 11 other calls in file

17
18
19
20
21
22
23
24
25
26
let schemas = fs.readdirSync(path.join(__dirname, schemaPath));
schemas = schemas.filter((s) => s.indexOf('.json') !== -1);

before(() => {
  const metaSchema = loadSchema(path.join(__dirname, 'json-schema.json'));
  tv4.addSchema('http://json-schema.org/draft-04/schema', metaSchema);
});
after(() => {
  tv4.reset();
});
fork icon4
star icon32
watch icon4

+ 3 other calls in file

34
35
36
37
38
39
40
41
42
43
    VendorStatus: require('../schemas/VendorStatus.json')
};

function _loadSchemas() {
    for (var schemaName in schemas) {
        tv4.addSchema(schemaName + '.json', schemas[schemaName]);
    }
}

function listValidTypes() {
fork icon0
star icon5
watch icon8

0
1
2
3
4
5
6
7
8
9
var TV4 = require('tv4');

module.exports = {

    addSchema: function (uri, schema) {
        return TV4.addSchema(uri, schema);
    },

    getSchema: function (uri) {
        return TV4.getSchema(uri);
fork icon1
star icon4
watch icon3

105
106
107
108
109
110
111
112
113
114
    exports.loadMetaschemaSync(default_metaschemaUri, default_metaschemaPath);
    if (!exports.metaschema) throw new Error('METASCHEMA not set!');
};

exports.addSchemaName = function(schema, name) {
    tv4.addSchema(name, schema);
};

exports.addSchemaNameFromDir = function(dir, name, cb) {
    /*
fork icon16
star icon3
watch icon22

+ 3 other calls in file

4
5
6
7
8
9
10
11
12
13
var tv4 = require('tv4');

//-------------------------------------------------------------------------

exports.addJsonSchema = function (uri, schema) {
  tv4.addSchema(uri, schema);
};

function validationErrorToString(e) {
  return (e.dataPath) ? e.dataPath + " -- " + e.message : e.message;
fork icon0
star icon2
watch icon9

+ 3 other calls in file

24
25
26
27
28
29
30
31
32
 * @param {string} [url]  URL/ID of the schema. Can be omitted if schema contains id property
 * @param {object} schema JSON Schema to add
 */
function preload(url, schema) {
  if (schema) {
    return tv4.addSchema(url, schema);
  }
  return tv4.addSchema(url);
}
fork icon0
star icon2
watch icon8

+ 29 other calls in file

26
27
28
29
30
31
32
33
34
35
if (err) {
  console.log(err);
} else {
  for (var id in refs) {
    // register resolved refs
    tv4.addSchema(id, refs[id]);
  }

  // validates the first passed schema
  console.log(tv4.validateResult(data, schemas[0]));
fork icon3
star icon0
watch icon2

+ 3 other calls in file

16
17
18
19
20
21
22
23
24
25
Object.keys(schemas)
  .map(function (key) {
    var capitalized = S(key).capitalize().s;
    var capitalizedSchema = capitalized + 'Schema'
    //Add Schema
    tv4.addSchema(capitalizedSchema, schemas[key]);

    function Model (doc) {
      Base.call(this, doc);
      this.me = capitalized;
fork icon0
star icon0
watch icon0