-
Notifications
You must be signed in to change notification settings - Fork 19
/
bundle_xarf.js
68 lines (63 loc) · 1.58 KB
/
bundle_xarf.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const $RefParser = require("@apidevtools/json-schema-ref-parser");
const jsonfile = require("jsonfile");
var schema = require("./xarf.schema.json");
var options = {
resolve: {
http: false,
},
};
function removeKeys(obj, keys, depth = 0) {
var index;
for (var prop in obj) {
// important check that this is objects own property
// not from prototype prop inherited
// eslint-disable-next-line no-prototype-builtins
if (obj.hasOwnProperty(prop)) {
switch (typeof obj[prop]) {
case "string":
index = keys.indexOf(prop);
if ((index > -1) & (depth > 0)) {
delete obj[prop];
}
break;
case "object":
removeKeys(obj[prop], keys, ++depth);
break;
}
}
}
}
$RefParser
.bundle(schema, options)
.then(function (schema) {
removeKeys(schema, ["$id", "$schema"]);
var file = "xarf_bundled.schema.json";
jsonfile.writeFile(file, schema, function (err) {
if (err != null) {
console.error(err);
process.exit(2);
}
console.error("done");
process.exit();
});
})
.catch(function (err) {
console.error(err);
});
$RefParser
.dereference(schema, options)
.then(function (schema) {
removeKeys(schema, ["$id", "$schema"]);
var file = "xarf_deref.schema.json";
jsonfile.writeFile(file, schema, function (err) {
if (err != null) {
console.error(err);
process.exit(2);
}
console.error("done");
process.exit();
});
})
.catch(function (err) {
console.error(err);
});