oas-toolkit 0.12.3 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/expand-allof.js +2 -2
- package/merger.js +36 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ The project provides the following functionality:
|
|
|
8
8
|
|
|
9
9
|
- Merge multiple OAS documents into a single file
|
|
10
10
|
- Add/patch values in place
|
|
11
|
-
- Remove
|
|
11
|
+
- Remove arbitrary keys from the specification
|
|
12
12
|
- Remove unused components
|
|
13
13
|
|
|
14
14
|
## Merge
|
package/expand-allof.js
CHANGED
|
@@ -22,8 +22,8 @@ module.exports = async function (oas, excludedPathMatcher) {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
oas = traverse(oas).map(function (x) {
|
|
25
|
-
const path = this.path.join("
|
|
26
|
-
if (
|
|
25
|
+
const path = "#/" + this.path.join("/");
|
|
26
|
+
if (excludedPathMatcher(path)) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
if (!this.node || !this.node["allOf"]) {
|
package/merger.js
CHANGED
|
@@ -1,24 +1,46 @@
|
|
|
1
|
-
const mergician = require("mergician");
|
|
2
1
|
const traverse = require("traverse");
|
|
3
2
|
const isEqual = require("lodash.isequal");
|
|
4
3
|
const uniqWith = require("lodash.uniqwith");
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const arrayBehaviour = {
|
|
6
|
+
openapi: "overwrite",
|
|
7
|
+
info: "overwrite",
|
|
8
|
+
servers: "overwrite",
|
|
9
|
+
externalDocs: "overwrite",
|
|
10
|
+
};
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
for (let
|
|
14
|
-
|
|
12
|
+
function deepMergeWithSpread(obj1, obj2) {
|
|
13
|
+
const result = { ...obj1 };
|
|
14
|
+
|
|
15
|
+
for (let key in obj2) {
|
|
16
|
+
if (obj2.hasOwnProperty(key)) {
|
|
17
|
+
if (obj2[key] instanceof Array && obj2[key] instanceof Array) {
|
|
18
|
+
let mode = "append";
|
|
19
|
+
if (arrayBehaviour[key]) {
|
|
20
|
+
mode = arrayBehaviour[key];
|
|
21
|
+
}
|
|
22
|
+
if (mode === "append" && result[key]) {
|
|
23
|
+
result[key] = result[key].concat(obj2[key]);
|
|
24
|
+
result[key] = uniqWith(result[key], isEqual);
|
|
25
|
+
} else {
|
|
26
|
+
result[key] = obj2[key];
|
|
27
|
+
}
|
|
28
|
+
} else if (obj2[key] instanceof Object && obj1[key] instanceof Object) {
|
|
29
|
+
result[key] = deepMergeWithSpread(obj1[key], obj2[key]);
|
|
30
|
+
} else {
|
|
31
|
+
result[key] = obj2[key];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
15
34
|
}
|
|
16
35
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function merge(objects) {
|
|
40
|
+
let combinedSpec = objects.shift();
|
|
41
|
+
|
|
42
|
+
for (let object of objects) {
|
|
43
|
+
combinedSpec = deepMergeWithSpread(combinedSpec, object);
|
|
22
44
|
}
|
|
23
45
|
|
|
24
46
|
// Values that should be unique
|
|
@@ -39,24 +61,6 @@ function merge(objects, options) {
|
|
|
39
61
|
return combinedSpec;
|
|
40
62
|
}
|
|
41
63
|
|
|
42
|
-
function mergeSection(spec, merger, objects, section) {
|
|
43
|
-
return Object.assign(
|
|
44
|
-
spec,
|
|
45
|
-
merger.apply(
|
|
46
|
-
null,
|
|
47
|
-
objects
|
|
48
|
-
.map((o) => {
|
|
49
|
-
const r = {};
|
|
50
|
-
if (o[section]) {
|
|
51
|
-
r[section] = o[section];
|
|
52
|
-
}
|
|
53
|
-
return r;
|
|
54
|
-
})
|
|
55
|
-
.filter(Boolean)
|
|
56
|
-
)
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
64
|
function ensureNoComponentColissions(objects, options) {
|
|
61
65
|
options = options || {};
|
|
62
66
|
const componentList = {};
|