@redocly/cli 1.0.0-beta.104 → 1.0.0-beta.107
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/bin/cli.js +1 -1
- package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -1
- package/lib/__mocks__/@redocly/openapi-core.js +2 -1
- package/lib/__mocks__/perf_hooks.js +1 -1
- package/lib/__mocks__/utils.d.ts +1 -1
- package/lib/__mocks__/utils.js +2 -2
- package/lib/__tests__/commands/bundle.test.js +52 -17
- package/lib/__tests__/commands/join.test.js +4 -4
- package/lib/__tests__/commands/lint.test.js +14 -8
- package/lib/__tests__/commands/push-region.test.js +2 -2
- package/lib/__tests__/commands/push.test.js +18 -18
- package/lib/__tests__/fixtures/config.d.ts +1 -1
- package/lib/__tests__/fixtures/config.js +1 -1
- package/lib/commands/bundle.d.ts +4 -12
- package/lib/commands/bundle.js +12 -11
- package/lib/commands/join.d.ts +1 -1
- package/lib/commands/join.js +105 -56
- package/lib/commands/lint.d.ts +3 -9
- package/lib/commands/lint.js +14 -11
- package/lib/commands/preview-docs/index.d.ts +3 -5
- package/lib/commands/preview-docs/index.js +14 -14
- package/lib/commands/push.d.ts +6 -6
- package/lib/commands/push.js +26 -26
- package/lib/commands/split/__tests__/index.test.js +8 -8
- package/lib/commands/split/index.d.ts +1 -1
- package/lib/commands/split/index.js +12 -11
- package/lib/commands/split/types.d.ts +2 -2
- package/lib/commands/split/types.js +2 -2
- package/lib/commands/stats.d.ts +1 -1
- package/lib/commands/stats.js +9 -7
- package/lib/index.js +12 -16
- package/lib/js-utils.js +2 -2
- package/lib/types.d.ts +13 -1
- package/lib/utils.d.ts +4 -4
- package/lib/utils.js +15 -17
- package/package.json +2 -2
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__mocks__/perf_hooks.ts +2 -2
- package/src/__mocks__/utils.ts +3 -1
- package/src/__tests__/commands/bundle.test.ts +71 -22
- package/src/__tests__/commands/join.test.ts +8 -8
- package/src/__tests__/commands/lint.test.ts +24 -11
- package/src/__tests__/commands/push-region.test.ts +2 -2
- package/src/__tests__/commands/push.test.ts +19 -24
- package/src/__tests__/fixtures/config.ts +1 -1
- package/src/__tests__/utils.test.ts +5 -8
- package/src/commands/bundle.ts +28 -40
- package/src/commands/join.ts +209 -119
- package/src/commands/lint.ts +30 -30
- package/src/commands/login.ts +2 -2
- package/src/commands/preview-docs/index.ts +33 -40
- package/src/commands/preview-docs/preview-server/preview-server.ts +6 -6
- package/src/commands/preview-docs/preview-server/server.ts +1 -1
- package/src/commands/push.ts +44 -53
- package/src/commands/split/__tests__/index.test.ts +47 -30
- package/src/commands/split/index.ts +84 -46
- package/src/commands/split/types.ts +19 -7
- package/src/commands/stats.ts +27 -24
- package/src/index.ts +16 -20
- package/src/js-utils.ts +2 -2
- package/src/types.ts +14 -1
- package/src/utils.ts +53 -53
- package/tsconfig.tsbuildinfo +1 -1
package/bin/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ export declare const RedoclyClient: jest.Mock<{
|
|
|
23
23
|
}, []>;
|
|
24
24
|
export declare const loadConfig: jest.Mock<{
|
|
25
25
|
configFile: null;
|
|
26
|
-
|
|
26
|
+
styleguide: {
|
|
27
27
|
addIgnore: jest.Mock<any, any>;
|
|
28
28
|
skipRules: jest.Mock<any, any>;
|
|
29
29
|
skipPreprocessors: jest.Mock<any, any>;
|
|
@@ -46,3 +46,4 @@ export declare const getTotals: jest.Mock<{
|
|
|
46
46
|
export declare const formatProblems: jest.Mock<any, any>;
|
|
47
47
|
export declare const slash: jest.Mock<any, any>;
|
|
48
48
|
export declare const findConfig: jest.Mock<any, any>;
|
|
49
|
+
export declare const doesYamlFileExist: jest.Mock<any, any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findConfig = exports.slash = exports.formatProblems = exports.getTotals = exports.bundle = exports.lint = exports.getMergedConfig = exports.loadConfig = exports.RedoclyClient = exports.__redoclyClient = void 0;
|
|
3
|
+
exports.doesYamlFileExist = exports.findConfig = exports.slash = exports.formatProblems = exports.getTotals = exports.bundle = exports.lint = exports.getMergedConfig = exports.loadConfig = exports.RedoclyClient = exports.__redoclyClient = void 0;
|
|
4
4
|
const config_1 = require("./../../__tests__/fixtures/config");
|
|
5
5
|
exports.__redoclyClient = {
|
|
6
6
|
isAuthorizedWithRedocly: jest.fn().mockResolvedValue(true),
|
|
@@ -25,3 +25,4 @@ exports.getTotals = jest.fn(() => ({ errors: 0 }));
|
|
|
25
25
|
exports.formatProblems = jest.fn();
|
|
26
26
|
exports.slash = jest.fn();
|
|
27
27
|
exports.findConfig = jest.fn();
|
|
28
|
+
exports.doesYamlFileExist = jest.fn();
|
package/lib/__mocks__/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const getFallbackApisOrExit: jest.Mock<any, [entrypoints: any]>;
|
|
3
3
|
export declare const dumpBundle: jest.Mock<string, []>;
|
|
4
4
|
export declare const slash: jest.Mock<any, any>;
|
|
5
5
|
export declare const pluralize: jest.Mock<any, any>;
|
package/lib/__mocks__/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exitWithError = exports.handleError = exports.getOutputFileName = exports.printLintTotals = exports.printUnusedWarnings = exports.printExecutionTime = exports.getExecutionTime = exports.pluralize = exports.slash = exports.dumpBundle = exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.exitWithError = exports.handleError = exports.getOutputFileName = exports.printLintTotals = exports.printUnusedWarnings = exports.printExecutionTime = exports.getExecutionTime = exports.pluralize = exports.slash = exports.dumpBundle = exports.getFallbackApisOrExit = void 0;
|
|
4
|
+
exports.getFallbackApisOrExit = jest.fn((entrypoints) => entrypoints.map((path) => ({ path })));
|
|
5
5
|
exports.dumpBundle = jest.fn(() => '');
|
|
6
6
|
exports.slash = jest.fn();
|
|
7
7
|
exports.pluralize = jest.fn();
|
|
@@ -11,9 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
13
13
|
const bundle_1 = require("../../commands/bundle");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
14
15
|
jest.mock('@redocly/openapi-core');
|
|
15
16
|
jest.mock('../../utils');
|
|
16
|
-
openapi_core_1.getMergedConfig.mockImplementation(config => config);
|
|
17
|
+
openapi_core_1.getMergedConfig.mockImplementation((config) => config);
|
|
17
18
|
describe('bundle', () => {
|
|
18
19
|
let processExitMock;
|
|
19
20
|
let exitCb;
|
|
@@ -28,22 +29,22 @@ describe('bundle', () => {
|
|
|
28
29
|
afterEach(() => {
|
|
29
30
|
openapi_core_1.lint.mockClear();
|
|
30
31
|
openapi_core_1.bundle.mockClear();
|
|
31
|
-
openapi_core_1.getTotals.
|
|
32
|
+
openapi_core_1.getTotals.mockReset();
|
|
32
33
|
});
|
|
33
34
|
it('bundles definitions w/o linting', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
const
|
|
35
|
+
const apis = ['foo.yaml', 'bar.yaml'];
|
|
35
36
|
yield bundle_1.handleBundle({
|
|
36
|
-
|
|
37
|
+
apis,
|
|
37
38
|
ext: 'yaml',
|
|
38
39
|
format: 'codeframe',
|
|
39
40
|
}, '1.0.0');
|
|
40
41
|
expect(openapi_core_1.lint).toBeCalledTimes(0);
|
|
41
|
-
expect(openapi_core_1.bundle).toBeCalledTimes(
|
|
42
|
+
expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
|
|
42
43
|
}));
|
|
43
44
|
it('exits with code 0 when bundles definitions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
const
|
|
45
|
+
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
45
46
|
yield bundle_1.handleBundle({
|
|
46
|
-
|
|
47
|
+
apis,
|
|
47
48
|
ext: 'yaml',
|
|
48
49
|
format: 'codeframe',
|
|
49
50
|
}, '1.0.0');
|
|
@@ -51,20 +52,25 @@ describe('bundle', () => {
|
|
|
51
52
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
52
53
|
}));
|
|
53
54
|
it('bundles definitions w/ linting', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const
|
|
55
|
+
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
56
|
+
openapi_core_1.getTotals.mockReturnValue({
|
|
57
|
+
errors: 0,
|
|
58
|
+
warnings: 0,
|
|
59
|
+
ignored: 0,
|
|
60
|
+
});
|
|
55
61
|
yield bundle_1.handleBundle({
|
|
56
|
-
|
|
62
|
+
apis,
|
|
57
63
|
ext: 'yaml',
|
|
58
64
|
format: 'codeframe',
|
|
59
65
|
lint: true,
|
|
60
66
|
}, '1.0.0');
|
|
61
|
-
expect(openapi_core_1.lint).toBeCalledTimes(
|
|
62
|
-
expect(openapi_core_1.bundle).toBeCalledTimes(
|
|
67
|
+
expect(openapi_core_1.lint).toBeCalledTimes(apis.length);
|
|
68
|
+
expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
|
|
63
69
|
}));
|
|
64
70
|
it('exits with code 0 when bundles definitions w/linting w/o errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
const
|
|
71
|
+
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
66
72
|
yield bundle_1.handleBundle({
|
|
67
|
-
|
|
73
|
+
apis,
|
|
68
74
|
ext: 'yaml',
|
|
69
75
|
format: 'codeframe',
|
|
70
76
|
lint: true,
|
|
@@ -73,20 +79,49 @@ describe('bundle', () => {
|
|
|
73
79
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
74
80
|
}));
|
|
75
81
|
it('exits with code 1 when bundles definitions w/linting w/errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
-
const
|
|
82
|
+
const apis = ['foo.yaml'];
|
|
77
83
|
openapi_core_1.getTotals.mockReturnValue({
|
|
78
84
|
errors: 1,
|
|
79
85
|
warnings: 0,
|
|
80
|
-
ignored: 0
|
|
86
|
+
ignored: 0,
|
|
81
87
|
});
|
|
82
88
|
yield bundle_1.handleBundle({
|
|
83
|
-
|
|
89
|
+
apis,
|
|
84
90
|
ext: 'yaml',
|
|
85
91
|
format: 'codeframe',
|
|
86
92
|
lint: true,
|
|
87
93
|
}, '1.0.0');
|
|
88
|
-
expect(openapi_core_1.lint).toBeCalledTimes(
|
|
94
|
+
expect(openapi_core_1.lint).toBeCalledTimes(apis.length);
|
|
89
95
|
exitCb === null || exitCb === void 0 ? void 0 : exitCb();
|
|
90
96
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
91
97
|
}));
|
|
98
|
+
it('handleError is called when bundles an invalid definition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
const apis = ['invalid.json'];
|
|
100
|
+
openapi_core_1.bundle.mockImplementationOnce(() => {
|
|
101
|
+
throw new Error('Invalid definition');
|
|
102
|
+
});
|
|
103
|
+
yield bundle_1.handleBundle({
|
|
104
|
+
apis,
|
|
105
|
+
ext: 'json',
|
|
106
|
+
format: 'codeframe',
|
|
107
|
+
lint: false,
|
|
108
|
+
}, '1.0.0');
|
|
109
|
+
expect(utils_1.handleError).toHaveBeenCalledTimes(1);
|
|
110
|
+
expect(utils_1.handleError).toHaveBeenCalledWith(new Error('Invalid definition'), 'invalid.json');
|
|
111
|
+
}));
|
|
112
|
+
it("handleError isn't called when bundles a valid definition", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const apis = ['foo.yaml'];
|
|
114
|
+
openapi_core_1.getTotals.mockReturnValue({
|
|
115
|
+
errors: 0,
|
|
116
|
+
warnings: 0,
|
|
117
|
+
ignored: 0,
|
|
118
|
+
});
|
|
119
|
+
yield bundle_1.handleBundle({
|
|
120
|
+
apis,
|
|
121
|
+
ext: 'yaml',
|
|
122
|
+
format: 'codeframe',
|
|
123
|
+
lint: false,
|
|
124
|
+
}, '1.0.0');
|
|
125
|
+
expect(utils_1.handleError).toHaveBeenCalledTimes(0);
|
|
126
|
+
}));
|
|
92
127
|
});
|
|
@@ -18,12 +18,12 @@ describe('handleJoin fails', () => {
|
|
|
18
18
|
const colloreteYellowMock = colorette_1.yellow;
|
|
19
19
|
colloreteYellowMock.mockImplementation((string) => string);
|
|
20
20
|
it('should call exitWithError because only one entrypoint', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
yield join_1.handleJoin({
|
|
22
|
-
expect(utils_1.exitWithError).toHaveBeenCalledWith(`At least 2
|
|
21
|
+
yield join_1.handleJoin({ apis: ['first.yaml'] }, 'cli-version');
|
|
22
|
+
expect(utils_1.exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided. \n\n`);
|
|
23
23
|
}));
|
|
24
24
|
it('should call exitWithError because passed all 3 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
25
|
yield join_1.handleJoin({
|
|
26
|
-
|
|
26
|
+
apis: ['first.yaml', 'second.yaml'],
|
|
27
27
|
'prefix-tags-with-info-prop': 'something',
|
|
28
28
|
'without-x-tag-groups': true,
|
|
29
29
|
'prefix-tags-with-filename': true,
|
|
@@ -32,7 +32,7 @@ describe('handleJoin fails', () => {
|
|
|
32
32
|
}));
|
|
33
33
|
it('should call exitWithError because passed all 2 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
34
|
yield join_1.handleJoin({
|
|
35
|
-
|
|
35
|
+
apis: ['first.yaml', 'second.yaml'],
|
|
36
36
|
'without-x-tag-groups': true,
|
|
37
37
|
'prefix-tags-with-filename': true,
|
|
38
38
|
}, 'cli-version');
|
|
@@ -18,7 +18,7 @@ jest.mock('@redocly/openapi-core');
|
|
|
18
18
|
jest.mock('../../utils');
|
|
19
19
|
jest.mock('perf_hooks');
|
|
20
20
|
const argvMock = {
|
|
21
|
-
|
|
21
|
+
apis: ['openapi.yaml'],
|
|
22
22
|
'lint-config': 'off',
|
|
23
23
|
format: 'codeframe',
|
|
24
24
|
};
|
|
@@ -36,19 +36,25 @@ describe('handleLint', () => {
|
|
|
36
36
|
return process.on(_e, cb);
|
|
37
37
|
});
|
|
38
38
|
getMergedConfigMock.mockReturnValue(config_1.ConfigFixture);
|
|
39
|
+
openapi_core_1.doesYamlFileExist.mockImplementation((path) => path === 'redocly.yaml');
|
|
39
40
|
});
|
|
40
41
|
afterEach(() => {
|
|
41
42
|
getMergedConfigMock.mockReset();
|
|
42
43
|
});
|
|
43
44
|
describe('loadConfig and getEnrtypoints stage', () => {
|
|
44
|
-
it('
|
|
45
|
+
it('should fail if config file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { config: 'config.yaml' }), versionMock);
|
|
47
|
+
expect(utils_1.exitWithError).toHaveBeenCalledWith('Please, provide valid path to the configuration file');
|
|
48
|
+
expect(openapi_core_1.loadConfig).toHaveBeenCalledTimes(0);
|
|
49
|
+
}));
|
|
50
|
+
it('should call loadConfig and getFallbackApisOrExit', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
51
|
yield lint_1.handleLint(argvMock, versionMock);
|
|
46
52
|
expect(openapi_core_1.loadConfig).toHaveBeenCalledWith(undefined, undefined, undefined);
|
|
47
|
-
expect(utils_1.
|
|
53
|
+
expect(utils_1.getFallbackApisOrExit).toHaveBeenCalled();
|
|
48
54
|
}));
|
|
49
55
|
it('should call loadConfig with args if such exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { config: '
|
|
51
|
-
expect(openapi_core_1.loadConfig).toHaveBeenCalledWith('
|
|
56
|
+
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { config: 'redocly.yaml', extends: ['some/path'] }), versionMock);
|
|
57
|
+
expect(openapi_core_1.loadConfig).toHaveBeenCalledWith('redocly.yaml', ['some/path'], undefined);
|
|
52
58
|
}));
|
|
53
59
|
it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
60
|
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { 'generate-ignore-file': true }), versionMock);
|
|
@@ -65,8 +71,8 @@ describe('handleLint', () => {
|
|
|
65
71
|
it('should call skipRules,skipPreprocessors and addIgnore with argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
72
|
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
67
73
|
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { 'skip-preprocessor': ['preprocessor'], 'skip-rule': ['rule'], 'generate-ignore-file': true }), versionMock);
|
|
68
|
-
expect(config_1.ConfigFixture.
|
|
69
|
-
expect(config_1.ConfigFixture.
|
|
74
|
+
expect(config_1.ConfigFixture.styleguide.skipRules).toHaveBeenCalledWith(['rule']);
|
|
75
|
+
expect(config_1.ConfigFixture.styleguide.skipPreprocessors).toHaveBeenCalledWith(['preprocessor']);
|
|
70
76
|
}));
|
|
71
77
|
it('should call formatProblems and getExecutionTime with argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
78
|
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
@@ -83,7 +89,7 @@ describe('handleLint', () => {
|
|
|
83
89
|
it('should catch error in handleError if something fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
90
|
openapi_core_1.lint.mockRejectedValueOnce('error');
|
|
85
91
|
yield lint_1.handleLint(argvMock, versionMock);
|
|
86
|
-
expect(utils_1.handleError).toHaveBeenCalledWith('error', '');
|
|
92
|
+
expect(utils_1.handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
|
|
87
93
|
}));
|
|
88
94
|
});
|
|
89
95
|
describe('erros and warning handle after lint stage', () => {
|
|
@@ -34,7 +34,7 @@ describe('push-with-region', () => {
|
|
|
34
34
|
redoclyClient.domain = 'redoc.ly';
|
|
35
35
|
yield push_1.handlePush({
|
|
36
36
|
upsert: true,
|
|
37
|
-
|
|
37
|
+
api: 'spec.json',
|
|
38
38
|
destination: '@org/my-api@1.0.0',
|
|
39
39
|
branchName: 'test',
|
|
40
40
|
});
|
|
@@ -45,7 +45,7 @@ describe('push-with-region', () => {
|
|
|
45
45
|
redoclyClient.domain = 'eu.redocly.com';
|
|
46
46
|
yield push_1.handlePush({
|
|
47
47
|
upsert: true,
|
|
48
|
-
|
|
48
|
+
api: 'spec.json',
|
|
49
49
|
destination: '@org/my-api@1.0.0',
|
|
50
50
|
branchName: 'test',
|
|
51
51
|
});
|
|
@@ -30,10 +30,10 @@ describe('push', () => {
|
|
|
30
30
|
it('pushes definition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
31
|
yield push_1.handlePush({
|
|
32
32
|
upsert: true,
|
|
33
|
-
|
|
33
|
+
api: 'spec.json',
|
|
34
34
|
destination: '@org/my-api@1.0.0',
|
|
35
35
|
branchName: 'test',
|
|
36
|
-
|
|
36
|
+
public: true,
|
|
37
37
|
'batch-id': '123',
|
|
38
38
|
'batch-size': 2,
|
|
39
39
|
});
|
|
@@ -55,10 +55,10 @@ describe('push', () => {
|
|
|
55
55
|
it('fails if batchId value is an empty string', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
56
|
yield push_1.handlePush({
|
|
57
57
|
upsert: true,
|
|
58
|
-
|
|
58
|
+
api: 'spec.json',
|
|
59
59
|
destination: '@org/my-api@1.0.0',
|
|
60
60
|
branchName: 'test',
|
|
61
|
-
|
|
61
|
+
public: true,
|
|
62
62
|
'batch-id': ' ',
|
|
63
63
|
'batch-size': 2,
|
|
64
64
|
});
|
|
@@ -67,10 +67,10 @@ describe('push', () => {
|
|
|
67
67
|
it('fails if batchSize value is less than 2', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
68
|
yield push_1.handlePush({
|
|
69
69
|
upsert: true,
|
|
70
|
-
|
|
70
|
+
api: 'spec.json',
|
|
71
71
|
destination: '@org/my-api@1.0.0',
|
|
72
72
|
branchName: 'test',
|
|
73
|
-
|
|
73
|
+
public: true,
|
|
74
74
|
'batch-id': '123',
|
|
75
75
|
'batch-size': 1,
|
|
76
76
|
});
|
|
@@ -81,23 +81,23 @@ describe('transformPush', () => {
|
|
|
81
81
|
it('should adapt the existing syntax', () => {
|
|
82
82
|
const cb = jest.fn();
|
|
83
83
|
push_1.transformPush(cb)({
|
|
84
|
-
|
|
84
|
+
maybeApiOrDestination: 'openapi.yaml',
|
|
85
85
|
maybeDestination: '@testing_org/main@v1',
|
|
86
86
|
});
|
|
87
87
|
expect(cb).toBeCalledWith({
|
|
88
|
-
|
|
88
|
+
api: 'openapi.yaml',
|
|
89
89
|
destination: '@testing_org/main@v1',
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
it('should adapt the existing syntax (including branchName)', () => {
|
|
93
93
|
const cb = jest.fn();
|
|
94
94
|
push_1.transformPush(cb)({
|
|
95
|
-
|
|
95
|
+
maybeApiOrDestination: 'openapi.yaml',
|
|
96
96
|
maybeDestination: '@testing_org/main@v1',
|
|
97
97
|
maybeBranchName: 'other',
|
|
98
98
|
});
|
|
99
99
|
expect(cb).toBeCalledWith({
|
|
100
|
-
|
|
100
|
+
api: 'openapi.yaml',
|
|
101
101
|
destination: '@testing_org/main@v1',
|
|
102
102
|
branchName: 'other',
|
|
103
103
|
});
|
|
@@ -105,13 +105,13 @@ describe('transformPush', () => {
|
|
|
105
105
|
it('should use --branch option firstly', () => {
|
|
106
106
|
const cb = jest.fn();
|
|
107
107
|
push_1.transformPush(cb)({
|
|
108
|
-
|
|
108
|
+
maybeApiOrDestination: 'openapi.yaml',
|
|
109
109
|
maybeDestination: '@testing_org/main@v1',
|
|
110
110
|
maybeBranchName: 'other',
|
|
111
111
|
branch: 'priority-branch',
|
|
112
112
|
});
|
|
113
113
|
expect(cb).toBeCalledWith({
|
|
114
|
-
|
|
114
|
+
api: 'openapi.yaml',
|
|
115
115
|
destination: '@testing_org/main@v1',
|
|
116
116
|
branchName: 'priority-branch',
|
|
117
117
|
});
|
|
@@ -119,7 +119,7 @@ describe('transformPush', () => {
|
|
|
119
119
|
it('should work for a destination only', () => {
|
|
120
120
|
const cb = jest.fn();
|
|
121
121
|
push_1.transformPush(cb)({
|
|
122
|
-
|
|
122
|
+
maybeApiOrDestination: '@testing_org/main@v1',
|
|
123
123
|
});
|
|
124
124
|
expect(cb).toBeCalledWith({
|
|
125
125
|
destination: '@testing_org/main@v1',
|
|
@@ -128,12 +128,12 @@ describe('transformPush', () => {
|
|
|
128
128
|
it('should accept aliases for the old syntax', () => {
|
|
129
129
|
const cb = jest.fn();
|
|
130
130
|
push_1.transformPush(cb)({
|
|
131
|
-
|
|
131
|
+
maybeApiOrDestination: 'alias',
|
|
132
132
|
maybeDestination: '@testing_org/main@v1',
|
|
133
133
|
});
|
|
134
134
|
expect(cb).toBeCalledWith({
|
|
135
135
|
destination: '@testing_org/main@v1',
|
|
136
|
-
|
|
136
|
+
api: 'alias',
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
it('should accept no arguments at all', () => {
|
|
@@ -164,7 +164,7 @@ describe('getDestinationProps', () => {
|
|
|
164
164
|
expect(push_1.getDestinationProps('main@v1', undefined)).toEqual([, 'main', 'v1']);
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
|
-
describe('
|
|
167
|
+
describe('getApiRoot', () => {
|
|
168
168
|
let config = {
|
|
169
169
|
apis: {
|
|
170
170
|
'main@v1': {
|
|
@@ -176,9 +176,9 @@ describe('getApiEntrypoint', () => {
|
|
|
176
176
|
},
|
|
177
177
|
};
|
|
178
178
|
it('should resolve the correct api for a valid name & version', () => {
|
|
179
|
-
expect(push_1.
|
|
179
|
+
expect(push_1.getApiRoot({ name: 'main', version: 'v1', config })).toEqual('openapi.yaml');
|
|
180
180
|
});
|
|
181
181
|
it('should resolve the latest version of api if there is no matching version', () => {
|
|
182
|
-
expect(push_1.
|
|
182
|
+
expect(push_1.getApiRoot({ name: 'main', version: 'latest', config })).toEqual('latest.yaml');
|
|
183
183
|
});
|
|
184
184
|
});
|
package/lib/commands/bundle.d.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function handleBundle(argv: {
|
|
4
|
-
entrypoints: string[];
|
|
1
|
+
import type { CommonOptions, OutputExtensions, Skips } from '../types';
|
|
2
|
+
export declare type BundleOptions = CommonOptions & Skips & {
|
|
5
3
|
output?: string;
|
|
6
4
|
ext: OutputExtensions;
|
|
7
|
-
'max-problems'?: number;
|
|
8
|
-
'skip-rule'?: string[];
|
|
9
|
-
'skip-preprocessor'?: string[];
|
|
10
|
-
'skip-decorator'?: string[];
|
|
11
5
|
dereferenced?: boolean;
|
|
12
6
|
force?: boolean;
|
|
13
|
-
config?: string;
|
|
14
7
|
lint?: boolean;
|
|
15
|
-
format: OutputFormat;
|
|
16
8
|
metafile?: string;
|
|
17
|
-
extends?: string[];
|
|
18
9
|
'remove-unused-components'?: boolean;
|
|
19
10
|
'keep-url-references'?: boolean;
|
|
20
|
-
}
|
|
11
|
+
};
|
|
12
|
+
export declare function handleBundle(argv: BundleOptions, version: string): Promise<void>;
|
package/lib/commands/bundle.js
CHANGED
|
@@ -31,19 +31,20 @@ function handleBundle(argv, version) {
|
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
32
|
const config = yield openapi_core_1.loadConfig(argv.config, argv.extends);
|
|
33
33
|
const removeUnusedComponents = argv['remove-unused-components'] &&
|
|
34
|
-
!((_b = (_a = config.rawConfig.
|
|
35
|
-
const
|
|
34
|
+
!((_b = (_a = config.rawConfig.styleguide) === null || _a === void 0 ? void 0 : _a.decorators) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('remove-unused-components'));
|
|
35
|
+
const apis = yield utils_1.getFallbackApisOrExit(argv.apis, config);
|
|
36
36
|
const totals = { errors: 0, warnings: 0, ignored: 0 };
|
|
37
37
|
const maxProblems = argv['max-problems'];
|
|
38
|
-
for (const { path, alias } of
|
|
38
|
+
for (const { path, alias } of apis) {
|
|
39
39
|
try {
|
|
40
40
|
const startedAt = perf_hooks_1.performance.now();
|
|
41
41
|
const resolvedConfig = openapi_core_1.getMergedConfig(config, alias);
|
|
42
|
-
resolvedConfig
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const { styleguide } = resolvedConfig;
|
|
43
|
+
styleguide.skipRules(argv['skip-rule']);
|
|
44
|
+
styleguide.skipPreprocessors(argv['skip-preprocessor']);
|
|
45
|
+
styleguide.skipDecorators(argv['skip-decorator']);
|
|
45
46
|
if (argv.lint) {
|
|
46
|
-
if (config.
|
|
47
|
+
if (config.styleguide.recommendedFallback) {
|
|
47
48
|
process.stderr.write(`No configurations were defined in extends -- using built in ${colorette_1.blue('recommended')} configuration by default.\n${colorette_1.red('Warning! This default behavior is going to be deprecated soon.')}\n\n`);
|
|
48
49
|
}
|
|
49
50
|
const results = yield openapi_core_1.lint({
|
|
@@ -71,7 +72,7 @@ function handleBundle(argv, version) {
|
|
|
71
72
|
keepUrlRefs: argv['keep-url-references'],
|
|
72
73
|
}), { bundle: result, problems } = _e, meta = __rest(_e, ["bundle", "problems"]);
|
|
73
74
|
const fileTotals = openapi_core_1.getTotals(problems);
|
|
74
|
-
const { outputFile, ext } = utils_1.getOutputFileName(path,
|
|
75
|
+
const { outputFile, ext } = utils_1.getOutputFileName(path, apis.length, argv.output, argv.ext);
|
|
75
76
|
if (fileTotals.errors === 0 || argv.force) {
|
|
76
77
|
if (!argv.output) {
|
|
77
78
|
const output = utils_1.dumpBundle(result.parsed, argv.ext || 'yaml', argv.dereferenced);
|
|
@@ -92,8 +93,8 @@ function handleBundle(argv, version) {
|
|
|
92
93
|
version,
|
|
93
94
|
});
|
|
94
95
|
if (argv.metafile) {
|
|
95
|
-
if (
|
|
96
|
-
process.stderr.write(colorette_1.yellow(`[WARNING] "--metafile" cannot be used with multiple
|
|
96
|
+
if (apis.length > 1) {
|
|
97
|
+
process.stderr.write(colorette_1.yellow(`[WARNING] "--metafile" cannot be used with multiple apis. Skipping...`));
|
|
97
98
|
}
|
|
98
99
|
{
|
|
99
100
|
fs_1.writeFileSync(argv.metafile, JSON.stringify(meta), 'utf-8');
|
|
@@ -120,7 +121,7 @@ function handleBundle(argv, version) {
|
|
|
120
121
|
utils_1.handleError(e, path);
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
|
-
utils_1.printUnusedWarnings(config.
|
|
124
|
+
utils_1.printUnusedWarnings(config.styleguide);
|
|
124
125
|
// defer process exit to allow STDOUT pipe to flush
|
|
125
126
|
// see https://github.com/nodejs/node-v0.x-archive/issues/3737#issuecomment-19156072
|
|
126
127
|
process.once('exit', () => process.exit(totals.errors === 0 || argv.force ? 0 : 1));
|
package/lib/commands/join.d.ts
CHANGED