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.
@@ -23,6 +23,10 @@ function run(oas) {
23
23
  isEqual
24
24
  ).filter((n) => n);
25
25
 
26
+ if (basePaths.length === 0) {
27
+ return oas;
28
+ }
29
+
26
30
  if (basePaths.length > 1) {
27
31
  throw new Error(
28
32
  `Base paths are different in the servers block. Found: ${basePaths.join(
@@ -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> <...more.yaml>",
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(
@@ -1,20 +1,22 @@
1
1
  const fs = require("fs");
2
2
  const yaml = require("js-yaml");
3
3
 
4
- module.exports = function ({ argv }) {
4
+ module.exports = function (argv, b, c) {
5
5
  try {
6
- const oasFiles = argv._.slice(1);
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
- const oas = [];
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas-toolkit",
3
- "version": "0.10.3",
3
+ "version": "0.11.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {