-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
merge-utils.js
52 lines (49 loc) · 1.17 KB
/
merge-utils.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
const dedupe = (methods1, methods2) => {
return methods2.reduce(
(arr, method) => {
if (arr.find((m) => m.name === method.name) === undefined) {
arr.push(method);
}
return arr;
},
methods1
);
};
const mergeOpenRPC = (first, second) => {
return {
openrpc: first.openrpc,
info: first.info,
methods: dedupe(first.methods, second.methods),
components: {
errors: {
...first.components.errors,
...second.components.errors
},
schemas: {
...first.components.schemas,
...second.components.schemas
},
tags: {
...first.components.tags,
...second.components.tags
},
contentDescriptors: {
...first.components.contentDescriptors,
...second.components.contentDescriptors
},
examplePairings: {
...first.components.examplePairings,
...second.components.examplePairings
},
links: {
...first.components.links,
...second.components.links
},
examples: {
...first.components.examples,
...second.components.examples
}
}
};
};
module.exports = mergeOpenRPC;