-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
35 lines (28 loc) · 1.05 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict'
const jsb = require('json-schema-builder');
const fs = require('fs');
const ZSchema = require('z-schema');
const validator = new ZSchema();
let schema = jsb.schema()
.properties({
id: jsb.integer(),
name: jsb.string(),
species: jsb.string(),
description: jsb.object()
.properties({
age: jsb.integer(),
mix: jsb.boolean(),
breed: jsb.type(['string', 'array'])
})
})
.required(['id', 'name', 'description'])
.additionalProperties(false);
let filepath = 'schema.json';
schema.save(filepath, (err) => {
if (err) throw err;
console.log(`Schema saved to ${filepath}!\n`);
console.log('==================\n');
let schema = JSON.parse(fs.readFileSync(filepath, 'utf8'));
let valid = validator.validateSchema(schema);
console.log(`${filepath} validated against Z-Schema: ${valid}\n`);
});