-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmerge.js
30 lines (23 loc) · 889 Bytes
/
merge.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
/**
* Utility code to merge an Open API document (generated for Concerto resources)
* with a fragment of an Open API document that defines additional paths.
*/
const fs = require('fs');
const base = fs.readFileSync('./output/openapi.json', 'utf8');
const baseJson = JSON.parse(base);
const extra = fs.readFileSync('./openapi-extra-paths.json', 'utf8');
const extraJson = JSON.parse(extra);
const mergedPaths = {};
Object.keys(baseJson.paths).forEach(pathKey => {
mergedPaths[pathKey] = baseJson.paths[pathKey];
});
Object.keys(extraJson.paths).forEach(pathKey => {
mergedPaths[pathKey] = extraJson.paths[pathKey];
});
const merged = {
...baseJson
};
merged.paths = mergedPaths;
merged.info.title = 'Accord Protocol';
merged.info.description = 'API for document generation and agreement automation';
fs.writeFileSync('./openapi.json', JSON.stringify(merged, null, 2));