-
Notifications
You must be signed in to change notification settings - Fork 157
/
schema-bundle.js
63 lines (55 loc) · 2.45 KB
/
schema-bundle.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
// Author: Chandan BN (c) 2021
// (2) creates a bundled schema
const rp = require('json-schema-ref-parser');
const fs = require('fs');
const dirName = process.argv[3];
if(!dirName) {
console.error('Please specify directory name');
process.exit(1);
}
async function schemaBundle() {
var cveSchemaBundle = await rp.bundle(process.argv[2]);
var metricProperties = cveSchemaBundle.definitions.metrics.items.properties;
delete metricProperties.cvssV4_0.$id;
delete metricProperties.cvssV3_1.id;
delete metricProperties.cvssV3_0.id;
delete metricProperties.cvssV2_0.id;
delete metricProperties.cvssV4_0.license;
delete metricProperties.cvssV3_1.license;
delete metricProperties.cvssV3_0.license;
delete metricProperties.cvssV2_0.license;
fs.writeFile(`${dirName}/CVE_Record_Format.json`,
JSON.stringify(cveSchemaBundle, null, 2),
err => {
if(err)
throw err;
else
console.log('CVE_Record_Format.json created');
}
);
for(let t of ['cnaPublishedContainer', 'cnaRejectedContainer', 'adpContainer']) {
var subSchema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": `https://cveproject.github.io/cve-schema/schema/docs/CVE_Record_Format_bundled_${t}.json`,
"title": `CVE Record Format ${t} sub schema`,
"description": `CVE Record Format ${t} format`,
"definitions": cveSchemaBundle.definitions,
"properties": {
},
"additionalProperties": false
}
subSchema.properties[t.replace(/Published|Rejected/,'')] = {
"$ref": `#/definitions/${t}`
}
fs.writeFile(`${dirName}/CVE_Record_Format_bundled_${t}.json`,
JSON.stringify(subSchema, null, 2),
err => {
if(err)
throw err;
else
console.log(`CVE_Record_Format_bundled_${t}.json created`);
}
);
}
}
schemaBundle();