oas-toolkit 0.10.3 → 0.11.0
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/canonical-server.js +4 -0
- package/canonical-server.test.js +16 -0
- package/cli/bin.js +7 -1
- package/cli/commands/merge.js +8 -6
- package/package.json +1 -1
package/canonical-server.js
CHANGED
package/canonical-server.test.js
CHANGED
|
@@ -43,6 +43,22 @@ describe("#run", () => {
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
it("is idempotent", () => {
|
|
47
|
+
const o = getOas(["https://api.example.com/v1"]);
|
|
48
|
+
|
|
49
|
+
const updatedOas = c.run(o);
|
|
50
|
+
expect(updatedOas.paths).toEqual({
|
|
51
|
+
"/v1/foo/hello": {},
|
|
52
|
+
"/v1/foo/world": {},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Run a second time
|
|
56
|
+
expect(c.run(updatedOas).paths).toEqual({
|
|
57
|
+
"/v1/foo/hello": {},
|
|
58
|
+
"/v1/foo/world": {},
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
46
62
|
it("handles multiple servers", () => {
|
|
47
63
|
const o = getOas([
|
|
48
64
|
"https://api.example.com/v1",
|
package/cli/bin.js
CHANGED
|
@@ -5,8 +5,14 @@ const { hideBin } = require("yargs/helpers");
|
|
|
5
5
|
|
|
6
6
|
yargs(hideBin(process.argv))
|
|
7
7
|
.command(
|
|
8
|
-
"merge <openapi
|
|
8
|
+
"merge <openapi...>",
|
|
9
9
|
"merge the provided OpenAPI files",
|
|
10
|
+
(yargs) => {
|
|
11
|
+
yargs.option("move-path-to-operation", {
|
|
12
|
+
demandOption: false,
|
|
13
|
+
type: "boolean",
|
|
14
|
+
});
|
|
15
|
+
},
|
|
10
16
|
require("./commands/merge")
|
|
11
17
|
)
|
|
12
18
|
.command(
|
package/cli/commands/merge.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const yaml = require("js-yaml");
|
|
3
3
|
|
|
4
|
-
module.exports = function (
|
|
4
|
+
module.exports = function (argv, b, c) {
|
|
5
5
|
try {
|
|
6
|
-
const oasFiles = argv.
|
|
7
|
-
if (oasFiles.length < 2) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
6
|
+
const oasFiles = argv.openapi;
|
|
10
7
|
|
|
11
8
|
const merger = require("../../merger");
|
|
9
|
+
const canonical = require("../../canonical-server");
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
let oas = [];
|
|
14
12
|
for (let f of oasFiles) {
|
|
15
13
|
oas.push(yaml.load(fs.readFileSync(f)));
|
|
16
14
|
}
|
|
17
15
|
|
|
16
|
+
if (argv.movePathToOperation) {
|
|
17
|
+
oas = oas.map((o) => canonical.run(o));
|
|
18
|
+
}
|
|
19
|
+
|
|
18
20
|
const combined = merger(oas, argv);
|
|
19
21
|
console.log(yaml.dump(combined));
|
|
20
22
|
} catch (e) {
|