@redocly/cli 1.18.1 → 1.20.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/CHANGELOG.md +24 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
- package/lib/__mocks__/@redocly/openapi-core.js +1 -0
- package/lib/__mocks__/fs.d.ts +0 -1
- package/lib/__mocks__/perf_hooks.d.ts +0 -1
- package/lib/__mocks__/redoc.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +21 -23
- package/lib/__tests__/commands/bundle.test.js +21 -30
- package/lib/__tests__/commands/join.test.js +101 -70
- package/lib/__tests__/commands/lint.test.js +54 -54
- package/lib/__tests__/commands/push-region.test.js +24 -25
- package/lib/__tests__/commands/push.test.js +269 -170
- package/lib/__tests__/fetch-with-timeout.test.js +3 -12
- package/lib/__tests__/fixtures/config.d.ts +0 -1
- package/lib/__tests__/utils.test.js +32 -37
- package/lib/__tests__/wrapper.test.js +31 -20
- package/lib/cms/api/__tests__/api.client.test.js +29 -38
- package/lib/cms/api/api-client.d.ts +0 -2
- package/lib/cms/api/api-client.js +107 -128
- package/lib/cms/api/api-keys.js +1 -2
- package/lib/cms/api/domains.js +1 -2
- package/lib/cms/commands/__tests__/push-status.test.js +251 -162
- package/lib/cms/commands/__tests__/push.test.js +120 -102
- package/lib/cms/commands/__tests__/utils.test.js +12 -21
- package/lib/cms/commands/push-status.d.ts +3 -2
- package/lib/cms/commands/push-status.js +94 -106
- package/lib/cms/commands/push.d.ts +3 -2
- package/lib/cms/commands/push.js +66 -74
- package/lib/cms/commands/utils.js +20 -34
- package/lib/commands/build-docs/index.d.ts +2 -2
- package/lib/commands/build-docs/index.js +8 -17
- package/lib/commands/build-docs/utils.d.ts +1 -1
- package/lib/commands/build-docs/utils.js +27 -39
- package/lib/commands/bundle.d.ts +2 -2
- package/lib/commands/bundle.js +70 -94
- package/lib/commands/join.d.ts +2 -2
- package/lib/commands/join.js +375 -388
- package/lib/commands/lint.d.ts +2 -2
- package/lib/commands/lint.js +64 -75
- package/lib/commands/login.d.ts +3 -2
- package/lib/commands/login.js +10 -22
- package/lib/commands/preview-docs/index.d.ts +2 -2
- package/lib/commands/preview-docs/index.js +93 -106
- package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
- package/lib/commands/preview-docs/preview-server/server.d.ts +1 -4
- package/lib/commands/preview-docs/preview-server/server.js +6 -6
- package/lib/commands/preview-project/constants.d.ts +1 -1
- package/lib/commands/preview-project/index.d.ts +2 -1
- package/lib/commands/preview-project/index.js +5 -14
- package/lib/commands/preview-project/types.d.ts +1 -1
- package/lib/commands/push.d.ts +9 -12
- package/lib/commands/push.js +180 -196
- package/lib/commands/split/__tests__/index.test.js +31 -25
- package/lib/commands/split/index.d.ts +2 -1
- package/lib/commands/split/index.js +20 -33
- package/lib/commands/stats.d.ts +2 -2
- package/lib/commands/stats.js +36 -47
- package/lib/index.js +34 -49
- package/lib/types.d.ts +4 -5
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
- package/lib/utils/fetch-with-timeout.js +7 -12
- package/lib/utils/getCommandNameFromArgs.d.ts +1 -1
- package/lib/utils/getCommandNameFromArgs.js +2 -4
- package/lib/utils/js-utils.js +6 -7
- package/lib/utils/miscellaneous.d.ts +4 -1
- package/lib/utils/miscellaneous.js +130 -152
- package/lib/utils/update-version-notifier.js +4 -13
- package/lib/wrapper.d.ts +9 -2
- package/lib/wrapper.js +27 -16
- package/package.json +3 -3
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__tests__/commands/build-docs.test.ts +5 -4
- package/src/__tests__/commands/join.test.ts +51 -51
- package/src/__tests__/commands/push-region.test.ts +10 -8
- package/src/__tests__/commands/push.test.ts +127 -102
- package/src/__tests__/utils.test.ts +1 -0
- package/src/__tests__/wrapper.test.ts +24 -2
- package/src/cms/api/api-client.ts +2 -1
- package/src/cms/commands/__tests__/push-status.test.ts +70 -56
- package/src/cms/commands/__tests__/push.test.ts +30 -24
- package/src/cms/commands/push-status.ts +8 -7
- package/src/cms/commands/push.ts +12 -9
- package/src/commands/build-docs/index.ts +10 -5
- package/src/commands/build-docs/utils.ts +4 -4
- package/src/commands/bundle.ts +14 -6
- package/src/commands/join.ts +6 -2
- package/src/commands/lint.ts +9 -3
- package/src/commands/login.ts +5 -2
- package/src/commands/preview-docs/index.ts +7 -1
- package/src/commands/preview-docs/preview-server/preview-server.ts +4 -3
- package/src/commands/preview-docs/preview-server/server.ts +2 -1
- package/src/commands/preview-project/constants.ts +1 -1
- package/src/commands/preview-project/index.ts +5 -4
- package/src/commands/preview-project/types.ts +1 -1
- package/src/commands/push.ts +15 -18
- package/src/commands/split/__tests__/index.test.ts +17 -6
- package/src/commands/split/index.ts +4 -2
- package/src/commands/stats.ts +13 -6
- package/src/index.ts +13 -7
- package/src/types.ts +2 -3
- package/src/utils/getCommandNameFromArgs.ts +1 -1
- package/src/utils/miscellaneous.ts +11 -1
- package/src/wrapper.ts +37 -11
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @redocly/cli
|
|
2
2
|
|
|
3
|
+
## 1.20.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added support for ESM plugins and importing of plugins directly from npm package: `@vendor/package/plugin.js` instead of `./node_modules/@vendor/package/plugin.js`.
|
|
8
|
+
- Added `info-license-strict` rule as a replacement of the `info-license-url` to support the OpenAPI 3.1 changes to allow identifier or URL license details.
|
|
9
|
+
- Changed plugins format to export a function instead of an object for compatibility with other Redocly products. The backwards compatibility with an old format of plugins is maintained.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Added support for webhooks in stats and fixed a crash that occurred when tags were not included in webhooks.
|
|
14
|
+
- Updated @redocly/openapi-core to v1.20.0.
|
|
15
|
+
|
|
16
|
+
## 1.19.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- Added support for AsyncAPI 3.0 description linting.
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Fixed an issue where `patternProperties` incorrectly caused linting errors due to a missing `PatternProperties` node.
|
|
25
|
+
- Updated @redocly/openapi-core to v1.19.0.
|
|
26
|
+
|
|
3
27
|
## 1.18.1
|
|
4
28
|
|
|
5
29
|
### 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) {
|
package/lib/__mocks__/fs.d.ts
CHANGED
package/lib/__mocks__/redoc.d.ts
CHANGED
|
@@ -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', () =>
|
|
36
|
-
const result =
|
|
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', () =>
|
|
34
|
+
});
|
|
35
|
+
it('should work correctly when calling handlerBuildCommand', async () => {
|
|
42
36
|
const processExitMock = jest.spyOn(process, 'exit').mockImplementation();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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', () =>
|
|
25
|
+
it('bundles definitions', async () => {
|
|
35
26
|
const apis = ['foo.yaml', 'bar.yaml'];
|
|
36
|
-
|
|
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', () =>
|
|
32
|
+
});
|
|
33
|
+
it('exits with code 0 when bundles definitions', async () => {
|
|
43
34
|
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
44
|
-
|
|
35
|
+
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
45
36
|
apis,
|
|
46
37
|
ext: 'yaml',
|
|
47
38
|
});
|
|
48
|
-
|
|
39
|
+
await exitCb?.();
|
|
49
40
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
50
|
-
})
|
|
51
|
-
it('exits with code 0 when bundles definitions w/o errors', () =>
|
|
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
|
-
|
|
44
|
+
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
54
45
|
apis,
|
|
55
46
|
ext: 'yaml',
|
|
56
47
|
});
|
|
57
|
-
|
|
48
|
+
await exitCb?.();
|
|
58
49
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
59
|
-
})
|
|
60
|
-
it('exits with code 1 when bundles definitions w/errors', () =>
|
|
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
|
-
|
|
58
|
+
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
68
59
|
apis,
|
|
69
60
|
ext: 'yaml',
|
|
70
61
|
});
|
|
71
|
-
|
|
62
|
+
await exitCb?.();
|
|
72
63
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
73
|
-
})
|
|
74
|
-
it('handleError is called when bundles an invalid definition', () =>
|
|
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
|
-
|
|
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", () =>
|
|
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
|
-
|
|
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', () =>
|
|
24
|
-
|
|
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', () =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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', () =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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', () =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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', () =>
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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', () =>
|
|
65
|
+
});
|
|
66
|
+
it('should call writeToFileByExtension function', async () => {
|
|
60
67
|
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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', () =>
|
|
76
|
+
});
|
|
77
|
+
it('should call writeToFileByExtension function for OpenAPI 3.1', async () => {
|
|
67
78
|
openapi_core_1.detectSpec.mockReturnValue('oas3_1');
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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', () =>
|
|
87
|
+
});
|
|
88
|
+
it('should call writeToFileByExtension function with custom output file', async () => {
|
|
74
89
|
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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', () =>
|
|
99
|
+
});
|
|
100
|
+
it('should call writeToFileByExtension function with json file extension', async () => {
|
|
82
101
|
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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', () =>
|
|
110
|
+
});
|
|
111
|
+
it('should call skipDecorators and skipPreprocessors', async () => {
|
|
89
112
|
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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', () =>
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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', () =>
|
|
50
|
-
|
|
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', () =>
|
|
54
|
-
|
|
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', () =>
|
|
63
|
-
|
|
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', () =>
|
|
71
|
-
|
|
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', () =>
|
|
75
|
-
|
|
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', () =>
|
|
79
|
-
|
|
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 ', () =>
|
|
86
|
-
|
|
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', () =>
|
|
85
|
+
});
|
|
86
|
+
it('should call skipRules,skipPreprocessors and addIgnore with argv', async () => {
|
|
92
87
|
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
93
|
-
|
|
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', () =>
|
|
96
|
+
});
|
|
97
|
+
it('should call formatProblems and getExecutionTime with argv', async () => {
|
|
98
98
|
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
99
|
-
|
|
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', () =>
|
|
108
|
+
});
|
|
109
|
+
it('should catch error in handleError if something fails', async () => {
|
|
110
110
|
openapi_core_1.lint.mockRejectedValueOnce('error');
|
|
111
|
-
|
|
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', () =>
|
|
117
|
-
|
|
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', () =>
|
|
119
|
+
});
|
|
120
|
+
it('should call exit with 0 if no errors', async () => {
|
|
121
121
|
miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
|
|
122
|
-
return
|
|
122
|
+
return { ...config_1.ConfigFixture };
|
|
123
123
|
});
|
|
124
|
-
|
|
125
|
-
|
|
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', () =>
|
|
127
|
+
});
|
|
128
|
+
it('should exit with 1 if total errors > 0', async () => {
|
|
129
129
|
openapi_core_1.getTotals.mockReturnValueOnce({ errors: 1 });
|
|
130
|
-
|
|
131
|
-
|
|
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', () =>
|
|
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
|
-
|
|
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
|
});
|