@redocly/cli 1.18.1 → 1.19.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.
Files changed (91) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
  3. package/lib/__mocks__/@redocly/openapi-core.js +1 -0
  4. package/lib/__mocks__/fs.d.ts +0 -1
  5. package/lib/__mocks__/perf_hooks.d.ts +0 -1
  6. package/lib/__mocks__/redoc.d.ts +0 -1
  7. package/lib/__tests__/commands/build-docs.test.js +21 -23
  8. package/lib/__tests__/commands/bundle.test.js +21 -30
  9. package/lib/__tests__/commands/join.test.js +101 -70
  10. package/lib/__tests__/commands/lint.test.js +54 -54
  11. package/lib/__tests__/commands/push-region.test.js +24 -25
  12. package/lib/__tests__/commands/push.test.js +269 -170
  13. package/lib/__tests__/fetch-with-timeout.test.js +3 -12
  14. package/lib/__tests__/fixtures/config.d.ts +0 -1
  15. package/lib/__tests__/utils.test.js +32 -37
  16. package/lib/__tests__/wrapper.test.js +31 -20
  17. package/lib/cms/api/__tests__/api.client.test.js +29 -38
  18. package/lib/cms/api/api-client.d.ts +0 -2
  19. package/lib/cms/api/api-client.js +106 -127
  20. package/lib/cms/api/api-keys.js +1 -2
  21. package/lib/cms/api/domains.js +1 -2
  22. package/lib/cms/commands/__tests__/push-status.test.js +251 -162
  23. package/lib/cms/commands/__tests__/push.test.js +120 -102
  24. package/lib/cms/commands/__tests__/utils.test.js +12 -21
  25. package/lib/cms/commands/push-status.d.ts +3 -2
  26. package/lib/cms/commands/push-status.js +94 -106
  27. package/lib/cms/commands/push.d.ts +3 -2
  28. package/lib/cms/commands/push.js +66 -74
  29. package/lib/cms/commands/utils.js +20 -34
  30. package/lib/commands/build-docs/index.d.ts +2 -2
  31. package/lib/commands/build-docs/index.js +8 -17
  32. package/lib/commands/build-docs/utils.js +26 -38
  33. package/lib/commands/bundle.d.ts +2 -2
  34. package/lib/commands/bundle.js +70 -94
  35. package/lib/commands/join.d.ts +2 -2
  36. package/lib/commands/join.js +375 -388
  37. package/lib/commands/lint.d.ts +2 -2
  38. package/lib/commands/lint.js +64 -75
  39. package/lib/commands/login.d.ts +3 -2
  40. package/lib/commands/login.js +9 -21
  41. package/lib/commands/preview-docs/index.d.ts +2 -2
  42. package/lib/commands/preview-docs/index.js +92 -106
  43. package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
  44. package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
  45. package/lib/commands/preview-docs/preview-server/server.js +6 -6
  46. package/lib/commands/preview-project/index.d.ts +2 -1
  47. package/lib/commands/preview-project/index.js +5 -14
  48. package/lib/commands/push.d.ts +8 -11
  49. package/lib/commands/push.js +177 -195
  50. package/lib/commands/split/__tests__/index.test.js +31 -25
  51. package/lib/commands/split/index.d.ts +2 -1
  52. package/lib/commands/split/index.js +20 -33
  53. package/lib/commands/stats.d.ts +2 -2
  54. package/lib/commands/stats.js +34 -45
  55. package/lib/index.js +32 -46
  56. package/lib/types.d.ts +2 -2
  57. package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
  58. package/lib/utils/fetch-with-timeout.js +7 -12
  59. package/lib/utils/getCommandNameFromArgs.js +2 -4
  60. package/lib/utils/js-utils.js +6 -7
  61. package/lib/utils/miscellaneous.d.ts +4 -1
  62. package/lib/utils/miscellaneous.js +130 -152
  63. package/lib/utils/update-version-notifier.js +4 -13
  64. package/lib/wrapper.d.ts +9 -2
  65. package/lib/wrapper.js +27 -16
  66. package/package.json +3 -3
  67. package/src/__mocks__/@redocly/openapi-core.ts +1 -0
  68. package/src/__tests__/commands/build-docs.test.ts +5 -4
  69. package/src/__tests__/commands/join.test.ts +51 -51
  70. package/src/__tests__/commands/push-region.test.ts +10 -8
  71. package/src/__tests__/commands/push.test.ts +127 -102
  72. package/src/__tests__/utils.test.ts +1 -0
  73. package/src/__tests__/wrapper.test.ts +24 -2
  74. package/src/cms/commands/__tests__/push-status.test.ts +70 -56
  75. package/src/cms/commands/__tests__/push.test.ts +30 -24
  76. package/src/cms/commands/push-status.ts +8 -7
  77. package/src/cms/commands/push.ts +12 -9
  78. package/src/commands/build-docs/index.ts +10 -5
  79. package/src/commands/bundle.ts +14 -6
  80. package/src/commands/join.ts +6 -2
  81. package/src/commands/lint.ts +9 -3
  82. package/src/commands/login.ts +4 -2
  83. package/src/commands/preview-docs/index.ts +6 -1
  84. package/src/commands/preview-project/index.ts +5 -4
  85. package/src/commands/push.ts +13 -15
  86. package/src/commands/split/__tests__/index.test.ts +17 -6
  87. package/src/commands/split/index.ts +4 -2
  88. package/src/commands/stats.ts +4 -2
  89. package/src/utils/miscellaneous.ts +11 -1
  90. package/src/wrapper.ts +37 -11
  91. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @redocly/cli
2
2
 
3
+ ## 1.19.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added support for AsyncAPI 3.0 description linting.
8
+
9
+ ### Patch Changes
10
+
11
+ - Fixed an issue where `patternProperties` incorrectly caused linting errors due to a missing `PatternProperties` node.
12
+ - Updated @redocly/openapi-core to v1.19.0.
13
+
3
14
  ## 1.18.1
4
15
 
5
16
  ### Patch Changes
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  import type { Document } from '@redocly/openapi-core';
3
2
  export declare const __redoclyClient: {
4
3
  isAuthorizedWithRedocly: jest.Mock<any, any>;
@@ -85,7 +84,8 @@ export declare enum SpecVersion {
85
84
  OAS2 = "oas2",
86
85
  OAS3_0 = "oas3_0",
87
86
  OAS3_1 = "oas3_1",
88
- Async2 = "async2"
87
+ Async2 = "async2",
88
+ Async3 = "async3"
89
89
  }
90
90
  export declare enum Oas3Operations {
91
91
  get = "get",
@@ -69,6 +69,7 @@ var SpecVersion;
69
69
  SpecVersion["OAS3_0"] = "oas3_0";
70
70
  SpecVersion["OAS3_1"] = "oas3_1";
71
71
  SpecVersion["Async2"] = "async2";
72
+ SpecVersion["Async3"] = "async3";
72
73
  })(SpecVersion || (exports.SpecVersion = SpecVersion = {}));
73
74
  var Oas3Operations;
74
75
  (function (Oas3Operations) {
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  export declare const existsSync: jest.Mock<any, any>;
3
2
  export declare const readFileSync: jest.Mock<string, []>;
4
3
  export declare const statSync: jest.Mock<{
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  export declare const performance: {
3
2
  now: jest.Mock<any, any>;
4
3
  };
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  export declare const loadAndBundleSpec: jest.Mock<Promise<{
3
2
  openapi: string;
4
3
  }>, []>;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const redoc_1 = require("redoc");
13
4
  const server_1 = require("react-dom/server");
@@ -32,25 +23,32 @@ jest.mock('handlebars', () => ({
32
23
  compile: jest.fn(() => jest.fn(() => '<html></html>')),
33
24
  }));
34
25
  describe('build-docs', () => {
35
- it('should return correct html and call function for ssr', () => __awaiter(void 0, void 0, void 0, function* () {
36
- const result = yield (0, utils_1.getPageHTML)({}, '../some-path/openapi.yaml', Object.assign(Object.assign({}, config), { redocCurrentVersion: '2.0.0' }));
26
+ it('should return correct html and call function for ssr', async () => {
27
+ const result = await (0, utils_1.getPageHTML)({}, '../some-path/openapi.yaml', {
28
+ ...config,
29
+ redocCurrentVersion: '2.0.0',
30
+ });
37
31
  expect(server_1.renderToString).toBeCalledTimes(1);
38
32
  expect(redoc_1.createStore).toBeCalledTimes(1);
39
33
  expect(result).toBe('<html></html>');
40
- }));
41
- it('should work correctly when calling handlerBuildCommand', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ });
35
+ it('should work correctly when calling handlerBuildCommand', async () => {
42
36
  const processExitMock = jest.spyOn(process, 'exit').mockImplementation();
43
- yield (0, build_docs_1.handlerBuildCommand)({
44
- o: '',
45
- title: 'test',
46
- disableGoogleFont: false,
47
- template: '',
48
- templateOptions: {},
49
- theme: { openapi: {} },
50
- api: '../some-path/openapi.yaml',
51
- }, {});
37
+ await (0, build_docs_1.handlerBuildCommand)({
38
+ argv: {
39
+ o: '',
40
+ title: 'test',
41
+ disableGoogleFont: false,
42
+ template: '',
43
+ templateOptions: {},
44
+ theme: { openapi: {} },
45
+ api: '../some-path/openapi.yaml',
46
+ },
47
+ config: {},
48
+ version: 'cli-version',
49
+ });
52
50
  expect(redoc_1.loadAndBundleSpec).toBeCalledTimes(1);
53
51
  expect(miscellaneous_1.getFallbackApisOrExit).toBeCalledTimes(1);
54
52
  expect(processExitMock).toBeCalledTimes(0);
55
- }));
53
+ });
56
54
  });
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const openapi_core_1 = require("@redocly/openapi-core");
13
4
  const bundle_1 = require("../../commands/bundle");
@@ -31,69 +22,69 @@ describe('bundle', () => {
31
22
  openapi_core_1.bundle.mockClear();
32
23
  openapi_core_1.getTotals.mockReset();
33
24
  });
34
- it('bundles definitions', () => __awaiter(void 0, void 0, void 0, function* () {
25
+ it('bundles definitions', async () => {
35
26
  const apis = ['foo.yaml', 'bar.yaml'];
36
- yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
27
+ await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
37
28
  apis,
38
29
  ext: 'yaml',
39
30
  });
40
31
  expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
41
- }));
42
- it('exits with code 0 when bundles definitions', () => __awaiter(void 0, void 0, void 0, function* () {
32
+ });
33
+ it('exits with code 0 when bundles definitions', async () => {
43
34
  const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
44
- yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
35
+ await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
45
36
  apis,
46
37
  ext: 'yaml',
47
38
  });
48
- yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
39
+ await exitCb?.();
49
40
  expect(processExitMock).toHaveBeenCalledWith(0);
50
- }));
51
- it('exits with code 0 when bundles definitions w/o errors', () => __awaiter(void 0, void 0, void 0, function* () {
41
+ });
42
+ it('exits with code 0 when bundles definitions w/o errors', async () => {
52
43
  const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
53
- yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
44
+ await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
54
45
  apis,
55
46
  ext: 'yaml',
56
47
  });
57
- yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
48
+ await exitCb?.();
58
49
  expect(processExitMock).toHaveBeenCalledWith(0);
59
- }));
60
- it('exits with code 1 when bundles definitions w/errors', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ });
51
+ it('exits with code 1 when bundles definitions w/errors', async () => {
61
52
  const apis = ['foo.yaml'];
62
53
  openapi_core_1.getTotals.mockReturnValue({
63
54
  errors: 1,
64
55
  warnings: 0,
65
56
  ignored: 0,
66
57
  });
67
- yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
58
+ await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
68
59
  apis,
69
60
  ext: 'yaml',
70
61
  });
71
- yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
62
+ await exitCb?.();
72
63
  expect(processExitMock).toHaveBeenCalledWith(1);
73
- }));
74
- it('handleError is called when bundles an invalid definition', () => __awaiter(void 0, void 0, void 0, function* () {
64
+ });
65
+ it('handleError is called when bundles an invalid definition', async () => {
75
66
  const apis = ['invalid.json'];
76
67
  openapi_core_1.bundle.mockImplementationOnce(() => {
77
68
  throw new Error('Invalid definition');
78
69
  });
79
- yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
70
+ await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
80
71
  apis,
81
72
  ext: 'json',
82
73
  });
83
74
  expect(miscellaneous_1.handleError).toHaveBeenCalledTimes(1);
84
75
  expect(miscellaneous_1.handleError).toHaveBeenCalledWith(new Error('Invalid definition'), 'invalid.json');
85
- }));
86
- it("handleError isn't called when bundles a valid definition", () => __awaiter(void 0, void 0, void 0, function* () {
76
+ });
77
+ it("handleError isn't called when bundles a valid definition", async () => {
87
78
  const apis = ['foo.yaml'];
88
79
  openapi_core_1.getTotals.mockReturnValue({
89
80
  errors: 0,
90
81
  warnings: 0,
91
82
  ignored: 0,
92
83
  });
93
- yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
84
+ await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
94
85
  apis,
95
86
  ext: 'yaml',
96
87
  });
97
88
  expect(miscellaneous_1.handleError).toHaveBeenCalledTimes(0);
98
- }));
89
+ });
99
90
  });
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const colorette_1 = require("colorette");
13
4
  const openapi_core_1 = require("@redocly/openapi-core");
@@ -20,87 +11,127 @@ jest.mock('colorette');
20
11
  describe('handleJoin', () => {
21
12
  const colloreteYellowMock = colorette_1.yellow;
22
13
  colloreteYellowMock.mockImplementation((string) => string);
23
- it('should call exitWithError because only one entrypoint', () => __awaiter(void 0, void 0, void 0, function* () {
24
- yield (0, join_1.handleJoin)({ apis: ['first.yaml'] }, {}, 'cli-version');
14
+ it('should call exitWithError because only one entrypoint', async () => {
15
+ await (0, join_1.handleJoin)({ argv: { apis: ['first.yaml'] }, config: {}, version: 'cli-version' });
25
16
  expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided.`);
26
- }));
27
- it('should call exitWithError because passed all 3 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
28
- yield (0, join_1.handleJoin)({
29
- apis: ['first.yaml', 'second.yaml'],
30
- 'prefix-tags-with-info-prop': 'something',
31
- 'without-x-tag-groups': true,
32
- 'prefix-tags-with-filename': true,
33
- }, {}, 'cli-version');
17
+ });
18
+ it('should call exitWithError because passed all 3 options for tags', async () => {
19
+ await (0, join_1.handleJoin)({
20
+ argv: {
21
+ apis: ['first.yaml', 'second.yaml'],
22
+ 'prefix-tags-with-info-prop': 'something',
23
+ 'without-x-tag-groups': true,
24
+ 'prefix-tags-with-filename': true,
25
+ },
26
+ config: {},
27
+ version: 'cli-version',
28
+ });
34
29
  expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, prefix-tags-with-info-prop, without-x-tag-groups together.\nPlease choose only one!`);
35
- }));
36
- it('should call exitWithError because passed all 2 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
37
- yield (0, join_1.handleJoin)({
38
- apis: ['first.yaml', 'second.yaml'],
39
- 'without-x-tag-groups': true,
40
- 'prefix-tags-with-filename': true,
41
- }, {}, 'cli-version');
30
+ });
31
+ it('should call exitWithError because passed all 2 options for tags', async () => {
32
+ await (0, join_1.handleJoin)({
33
+ argv: {
34
+ apis: ['first.yaml', 'second.yaml'],
35
+ 'without-x-tag-groups': true,
36
+ 'prefix-tags-with-filename': true,
37
+ },
38
+ config: {},
39
+ version: 'cli-version',
40
+ });
42
41
  expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, without-x-tag-groups together.\nPlease choose only one!`);
43
- }));
44
- it('should call exitWithError because Only OpenAPI 3.0 and OpenAPI 3.1 are supported', () => __awaiter(void 0, void 0, void 0, function* () {
45
- yield (0, join_1.handleJoin)({
46
- apis: ['first.yaml', 'second.yaml'],
47
- }, config_1.ConfigFixture, 'cli-version');
42
+ });
43
+ it('should call exitWithError because Only OpenAPI 3.0 and OpenAPI 3.1 are supported', async () => {
44
+ await (0, join_1.handleJoin)({
45
+ argv: {
46
+ apis: ['first.yaml', 'second.yaml'],
47
+ },
48
+ config: config_1.ConfigFixture,
49
+ version: 'cli-version',
50
+ });
48
51
  expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('Only OpenAPI 3.0 and OpenAPI 3.1 are supported: undefined.');
49
- }));
50
- it('should call exitWithError if mixing OpenAPI 3.0 and 3.1', () => __awaiter(void 0, void 0, void 0, function* () {
52
+ });
53
+ it('should call exitWithError if mixing OpenAPI 3.0 and 3.1', async () => {
51
54
  openapi_core_1.detectSpec
52
55
  .mockImplementationOnce(() => 'oas3_0')
53
56
  .mockImplementationOnce(() => 'oas3_1');
54
- yield (0, join_1.handleJoin)({
55
- apis: ['first.yaml', 'second.yaml'],
56
- }, config_1.ConfigFixture, 'cli-version');
57
+ await (0, join_1.handleJoin)({
58
+ argv: {
59
+ apis: ['first.yaml', 'second.yaml'],
60
+ },
61
+ config: config_1.ConfigFixture,
62
+ version: 'cli-version',
63
+ });
57
64
  expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('All APIs must use the same OpenAPI version: undefined.');
58
- }));
59
- it('should call writeToFileByExtension function', () => __awaiter(void 0, void 0, void 0, function* () {
65
+ });
66
+ it('should call writeToFileByExtension function', async () => {
60
67
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
61
- yield (0, join_1.handleJoin)({
62
- apis: ['first.yaml', 'second.yaml'],
63
- }, config_1.ConfigFixture, 'cli-version');
68
+ await (0, join_1.handleJoin)({
69
+ argv: {
70
+ apis: ['first.yaml', 'second.yaml'],
71
+ },
72
+ config: config_1.ConfigFixture,
73
+ version: 'cli-version',
74
+ });
64
75
  expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
65
- }));
66
- it('should call writeToFileByExtension function for OpenAPI 3.1', () => __awaiter(void 0, void 0, void 0, function* () {
76
+ });
77
+ it('should call writeToFileByExtension function for OpenAPI 3.1', async () => {
67
78
  openapi_core_1.detectSpec.mockReturnValue('oas3_1');
68
- yield (0, join_1.handleJoin)({
69
- apis: ['first.yaml', 'second.yaml'],
70
- }, config_1.ConfigFixture, 'cli-version');
79
+ await (0, join_1.handleJoin)({
80
+ argv: {
81
+ apis: ['first.yaml', 'second.yaml'],
82
+ },
83
+ config: config_1.ConfigFixture,
84
+ version: 'cli-version',
85
+ });
71
86
  expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
72
- }));
73
- it('should call writeToFileByExtension function with custom output file', () => __awaiter(void 0, void 0, void 0, function* () {
87
+ });
88
+ it('should call writeToFileByExtension function with custom output file', async () => {
74
89
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
75
- yield (0, join_1.handleJoin)({
76
- apis: ['first.yaml', 'second.yaml'],
77
- output: 'output.yml',
78
- }, config_1.ConfigFixture, 'cli-version');
90
+ await (0, join_1.handleJoin)({
91
+ argv: {
92
+ apis: ['first.yaml', 'second.yaml'],
93
+ output: 'output.yml',
94
+ },
95
+ config: config_1.ConfigFixture,
96
+ version: 'cli-version',
97
+ });
79
98
  expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'output.yml', expect.any(Boolean));
80
- }));
81
- it('should call writeToFileByExtension function with json file extension', () => __awaiter(void 0, void 0, void 0, function* () {
99
+ });
100
+ it('should call writeToFileByExtension function with json file extension', async () => {
82
101
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
83
- yield (0, join_1.handleJoin)({
84
- apis: ['first.json', 'second.yaml'],
85
- }, config_1.ConfigFixture, 'cli-version');
102
+ await (0, join_1.handleJoin)({
103
+ argv: {
104
+ apis: ['first.json', 'second.yaml'],
105
+ },
106
+ config: config_1.ConfigFixture,
107
+ version: 'cli-version',
108
+ });
86
109
  expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.json', expect.any(Boolean));
87
- }));
88
- it('should call skipDecorators and skipPreprocessors', () => __awaiter(void 0, void 0, void 0, function* () {
110
+ });
111
+ it('should call skipDecorators and skipPreprocessors', async () => {
89
112
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
90
- yield (0, join_1.handleJoin)({
91
- apis: ['first.yaml', 'second.yaml'],
92
- }, config_1.ConfigFixture, 'cli-version');
113
+ await (0, join_1.handleJoin)({
114
+ argv: {
115
+ apis: ['first.yaml', 'second.yaml'],
116
+ },
117
+ config: config_1.ConfigFixture,
118
+ version: 'cli-version',
119
+ });
93
120
  const config = (0, openapi_core_2.loadConfig)();
94
121
  expect(config.styleguide.skipDecorators).toHaveBeenCalled();
95
122
  expect(config.styleguide.skipPreprocessors).toHaveBeenCalled();
96
- }));
97
- it('should handle join with prefix-components-with-info-prop and null values', () => __awaiter(void 0, void 0, void 0, function* () {
123
+ });
124
+ it('should handle join with prefix-components-with-info-prop and null values', async () => {
98
125
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
99
- yield (0, join_1.handleJoin)({
100
- apis: ['first.yaml', 'second.yaml', 'third.yaml'],
101
- 'prefix-components-with-info-prop': 'title',
102
- output: 'join-result.yaml',
103
- }, config_1.ConfigFixture, 'cli-version');
126
+ await (0, join_1.handleJoin)({
127
+ argv: {
128
+ apis: ['first.yaml', 'second.yaml', 'third.yaml'],
129
+ 'prefix-components-with-info-prop': 'title',
130
+ output: 'join-result.yaml',
131
+ },
132
+ config: config_1.ConfigFixture,
133
+ version: 'cli-version',
134
+ });
104
135
  expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith({
105
136
  openapi: '3.0.0',
106
137
  info: {
@@ -216,5 +247,5 @@ describe('handleJoin', () => {
216
247
  },
217
248
  ],
218
249
  }, 'join-result.yaml', true);
219
- }));
250
+ });
220
251
  });
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const lint_1 = require("../../commands/lint");
13
4
  const openapi_core_1 = require("@redocly/openapi-core");
@@ -46,57 +37,66 @@ describe('handleLint', () => {
46
37
  getMergedConfigMock.mockReset();
47
38
  });
48
39
  describe('loadConfig and getEnrtypoints stage', () => {
49
- it('should fail if config file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
50
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'config.yaml' }));
40
+ it('should fail if config file does not exist', async () => {
41
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({ ...argvMock, config: 'config.yaml' });
51
42
  expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('Please provide a valid path to the configuration file.');
52
- }));
53
- it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', () => __awaiter(void 0, void 0, void 0, function* () {
54
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
43
+ });
44
+ it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', async () => {
45
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
55
46
  expect(miscellaneous_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
56
47
  configPath: undefined,
57
48
  customExtends: undefined,
58
49
  processRawConfig: undefined,
59
50
  });
60
51
  expect(miscellaneous_1.getFallbackApisOrExit).toHaveBeenCalled();
61
- }));
62
- it('should call loadConfig with args if such exist', () => __awaiter(void 0, void 0, void 0, function* () {
63
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'redocly.yaml', extends: ['some/path'] }));
52
+ });
53
+ it('should call loadConfig with args if such exist', async () => {
54
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({
55
+ ...argvMock,
56
+ config: 'redocly.yaml',
57
+ extends: ['some/path'],
58
+ });
64
59
  expect(miscellaneous_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
65
60
  configPath: 'redocly.yaml',
66
61
  customExtends: ['some/path'],
67
62
  processRawConfig: undefined,
68
63
  });
69
- }));
70
- it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', () => __awaiter(void 0, void 0, void 0, function* () {
71
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'generate-ignore-file': true }));
64
+ });
65
+ it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', async () => {
66
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({ ...argvMock, 'generate-ignore-file': true });
72
67
  expect(getMergedConfigMock).toHaveBeenCalled();
73
- }));
74
- it('should check if ruleset exist', () => __awaiter(void 0, void 0, void 0, function* () {
75
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
68
+ });
69
+ it('should check if ruleset exist', async () => {
70
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
76
71
  expect(miscellaneous_1.checkIfRulesetExist).toHaveBeenCalledTimes(1);
77
- }));
78
- it('should fail if apis not provided', () => __awaiter(void 0, void 0, void 0, function* () {
79
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { apis: [] }));
72
+ });
73
+ it('should fail if apis not provided', async () => {
74
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({ ...argvMock, apis: [] });
80
75
  expect(miscellaneous_1.getFallbackApisOrExit).toHaveBeenCalledTimes(1);
81
76
  expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('No APIs were provided.');
82
- }));
77
+ });
83
78
  });
84
79
  describe('loop through entrypoints and lint stage', () => {
85
- it('should call getMergedConfig and lint ', () => __awaiter(void 0, void 0, void 0, function* () {
86
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
80
+ it('should call getMergedConfig and lint ', async () => {
81
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
87
82
  expect(perf_hooks_1.performance.now).toHaveBeenCalled();
88
83
  expect(getMergedConfigMock).toHaveBeenCalled();
89
84
  expect(openapi_core_1.lint).toHaveBeenCalled();
90
- }));
91
- it('should call skipRules,skipPreprocessors and addIgnore with argv', () => __awaiter(void 0, void 0, void 0, function* () {
85
+ });
86
+ it('should call skipRules,skipPreprocessors and addIgnore with argv', async () => {
92
87
  openapi_core_1.lint.mockResolvedValueOnce(['problem']);
93
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'skip-preprocessor': ['preprocessor'], 'skip-rule': ['rule'], 'generate-ignore-file': true }));
88
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({
89
+ ...argvMock,
90
+ 'skip-preprocessor': ['preprocessor'],
91
+ 'skip-rule': ['rule'],
92
+ 'generate-ignore-file': true,
93
+ });
94
94
  expect(config_1.ConfigFixture.styleguide.skipRules).toHaveBeenCalledWith(['rule']);
95
95
  expect(config_1.ConfigFixture.styleguide.skipPreprocessors).toHaveBeenCalledWith(['preprocessor']);
96
- }));
97
- it('should call formatProblems and getExecutionTime with argv', () => __awaiter(void 0, void 0, void 0, function* () {
96
+ });
97
+ it('should call formatProblems and getExecutionTime with argv', async () => {
98
98
  openapi_core_1.lint.mockResolvedValueOnce(['problem']);
99
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'max-problems': 2, format: 'stylish' }));
99
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({ ...argvMock, 'max-problems': 2, format: 'stylish' });
100
100
  expect(openapi_core_1.getTotals).toHaveBeenCalledWith(['problem']);
101
101
  expect(openapi_core_1.formatProblems).toHaveBeenCalledWith(['problem'], {
102
102
  format: 'stylish',
@@ -105,33 +105,33 @@ describe('handleLint', () => {
105
105
  version: '1.0.0',
106
106
  });
107
107
  expect(miscellaneous_1.getExecutionTime).toHaveBeenCalledWith(42);
108
- }));
109
- it('should catch error in handleError if something fails', () => __awaiter(void 0, void 0, void 0, function* () {
108
+ });
109
+ it('should catch error in handleError if something fails', async () => {
110
110
  openapi_core_1.lint.mockRejectedValueOnce('error');
111
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
111
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
112
112
  expect(miscellaneous_1.handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
113
- }));
113
+ });
114
114
  });
115
115
  describe('erros and warning handle after lint stage', () => {
116
- it('should call printLintTotals and printLintTotals', () => __awaiter(void 0, void 0, void 0, function* () {
117
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
116
+ it('should call printLintTotals and printLintTotals', async () => {
117
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
118
118
  expect(miscellaneous_1.printUnusedWarnings).toHaveBeenCalled();
119
- }));
120
- it('should call exit with 0 if no errors', () => __awaiter(void 0, void 0, void 0, function* () {
119
+ });
120
+ it('should call exit with 0 if no errors', async () => {
121
121
  miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
122
- return Object.assign({}, config_1.ConfigFixture);
122
+ return { ...config_1.ConfigFixture };
123
123
  });
124
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
125
- yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
124
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
125
+ await exitCb?.();
126
126
  expect(processExitMock).toHaveBeenCalledWith(0);
127
- }));
128
- it('should exit with 1 if total errors > 0', () => __awaiter(void 0, void 0, void 0, function* () {
127
+ });
128
+ it('should exit with 1 if total errors > 0', async () => {
129
129
  openapi_core_1.getTotals.mockReturnValueOnce({ errors: 1 });
130
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
131
- yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
130
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
131
+ await exitCb?.();
132
132
  expect(processExitMock).toHaveBeenCalledWith(1);
133
- }));
134
- it('should use recommended fallback if no config', () => __awaiter(void 0, void 0, void 0, function* () {
133
+ });
134
+ it('should use recommended fallback if no config', async () => {
135
135
  openapi_core_1.getMergedConfig.mockImplementation(() => {
136
136
  return {
137
137
  styleguide: {
@@ -142,8 +142,8 @@ describe('handleLint', () => {
142
142
  },
143
143
  };
144
144
  });
145
- yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
145
+ await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
146
146
  expect(process.stderr.write).toHaveBeenCalledWith(`No configurations were provided -- using built in ${(0, colorette_1.blue)('recommended')} configuration by default.\n\n`);
147
- }));
147
+ });
148
148
  });
149
149
  });