@redocly/cli 1.3.0 → 1.4.1
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 +19 -0
- package/README.md +15 -7
- package/lib/__mocks__/@redocly/openapi-core.d.ts +1 -0
- package/lib/__mocks__/@redocly/openapi-core.js +4 -3
- package/lib/__mocks__/utils.d.ts +2 -0
- package/lib/__mocks__/utils.js +3 -1
- package/lib/__tests__/commands/build-docs.test.js +2 -2
- package/lib/__tests__/commands/bundle.test.js +7 -7
- package/lib/__tests__/commands/join.test.js +25 -18
- package/lib/__tests__/commands/lint.test.js +15 -15
- package/lib/__tests__/commands/push-region.test.js +2 -2
- package/lib/__tests__/commands/push.test.js +30 -30
- package/lib/__tests__/fetch-with-timeout.test.js +2 -2
- package/lib/__tests__/utils.test.js +63 -32
- package/lib/__tests__/wrapper.test.js +3 -3
- package/lib/assert-node-version.js +1 -1
- package/lib/commands/build-docs/index.js +9 -9
- package/lib/commands/build-docs/types.d.ts +2 -2
- package/lib/commands/build-docs/utils.js +10 -10
- package/lib/commands/bundle.d.ts +1 -1
- package/lib/commands/bundle.js +25 -25
- package/lib/commands/join.d.ts +1 -1
- package/lib/commands/join.js +49 -48
- package/lib/commands/lint.d.ts +1 -1
- package/lib/commands/lint.js +22 -22
- package/lib/commands/login.d.ts +1 -1
- package/lib/commands/login.js +3 -3
- package/lib/commands/preview-docs/index.d.ts +1 -1
- package/lib/commands/preview-docs/index.js +7 -7
- package/lib/commands/preview-docs/preview-server/hot.js +19 -2
- package/lib/commands/preview-docs/preview-server/preview-server.js +15 -14
- package/lib/commands/preview-docs/preview-server/server.d.ts +3 -1
- package/lib/commands/preview-docs/preview-server/server.js +2 -2
- package/lib/commands/push.d.ts +2 -2
- package/lib/commands/push.js +31 -31
- package/lib/commands/split/__tests__/index.test.js +9 -9
- package/lib/commands/split/index.d.ts +2 -2
- package/lib/commands/split/index.js +41 -40
- 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 -9
- package/lib/fetch-with-timeout.js +5 -2
- package/lib/index.js +11 -12
- package/lib/types.d.ts +6 -6
- package/lib/update-version-notifier.js +18 -18
- package/lib/utils.d.ts +6 -3
- package/lib/utils.js +66 -38
- package/lib/wrapper.js +5 -5
- package/package.json +4 -3
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__mocks__/utils.ts +2 -0
- package/src/__tests__/commands/join.test.ts +37 -7
- package/src/__tests__/utils.test.ts +45 -1
- package/src/commands/join.ts +8 -3
- package/src/commands/preview-docs/preview-server/hot.js +19 -2
- package/src/commands/preview-docs/preview-server/preview-server.ts +6 -4
- package/src/commands/preview-docs/preview-server/server.ts +2 -2
- package/src/commands/split/__tests__/index.test.ts +14 -5
- package/src/commands/split/index.ts +25 -17
- package/src/fetch-with-timeout.ts +3 -0
- package/src/index.ts +0 -1
- package/src/utils.ts +40 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @redocly/cli
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed an issue with resolving the `node-fetch` package by explicitly adding the missing dependency.
|
|
8
|
+
- Updated @redocly/openapi-core to v1.4.1.
|
|
9
|
+
|
|
10
|
+
## 1.4.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- Added `recommended-strict` ruleset which uses the same rules as `recommended` but with the severity level set to `error` for all rules.
|
|
15
|
+
- Add JSON output support to the `split` and `join` commands.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- The `--host/-h` argument in the `preview-docs` command is now also used by the WebSocket server for hot reloading.
|
|
20
|
+
- Updated @redocly/openapi-core to v1.4.0.
|
|
21
|
+
|
|
3
22
|
## 1.3.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Redocly CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[@Redocly](https://redocly.com) CLI is your all-in-one OpenAPI utility. It builds, manages, improves, and quality-checks your OpenAPI descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make API governance easy, and publish beautiful API reference documentation. Supports OpenAPI 3.1, 3.0 and OpenAPI 2.0 (legacy Swagger).
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|

|
|
7
7
|

|
|
8
8
|
|
|
9
|
-

|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
@@ -61,19 +61,27 @@ Your API reference docs are in `redoc-static.html` by default. You can customize
|
|
|
61
61
|
|
|
62
62
|
> :bulb: Redocly also has [hosted API reference docs](https://redocly.com/docs/api-registry/guides/api-registry-quickstart/), a (commercial) alternative to Redoc. Both Redoc and Redocly API reference docs can be worked on locally using the `preview-docs` command.
|
|
63
63
|
|
|
64
|
-
###
|
|
64
|
+
### Bundle multiple OpenAPI documents
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
Having one massive OpenAPI description can be annoying, so most people split them up into multiple documents via `$ref`, only to later find out some tools don't support `$ref`, or don't support multiple documents?! Well fear not, because Redocly has a `bundle` command you can use to recombine all of those documents back into one single document. The bundled output Redocly CLI provides is clean, tidy, and looks like a human made it.
|
|
67
|
+
|
|
68
|
+
### Automate API guidelines with Linting
|
|
69
|
+
|
|
70
|
+
Check your API matches the expected API guidelines by using the `lint` command. API guidelines are an important piece of API governance, it helps to keep APIs consistent (enforcing the same standards and naming conventions) but can also guide API teams through potential security hazards and other pitfalls. Automating API guidelines means you can keep APIs consistent and secure throughout their lifecycle. Even better, you can shape the design of the API before it even exists if you combine API linting with a design-first API workflow!
|
|
71
|
+
|
|
72
|
+
Our API linter is designed for speed on even large documents, and it's easy to run locally, in CI, or anywhere you need it. It's also designed for humans, with meaningful error messages to help you get your API right every time.
|
|
73
|
+
|
|
74
|
+
Try it like this:
|
|
67
75
|
|
|
68
76
|
```
|
|
69
77
|
redocly lint openapi.yaml
|
|
70
78
|
```
|
|
71
79
|
|
|
72
|
-
**Configure the rules** as you wish.
|
|
80
|
+
**Configure the rules** as you wish. Other API Linters use complicated identifiers like JSONPath, but Redocly makes life easy with simple expressions that understand the OpenAPI structure. You can either use the [built-in rules](https://redocly.com/docs/cli/rules) to mix-and-match your ideal API guidelines, or break out the tools to build your own.
|
|
73
81
|
|
|
74
|
-
**Format the output** in whatever way you need, the `stylish` output is as good as it sounds, but if you need JSON or Checkstyle outputs to integrate with other tools,
|
|
82
|
+
**Format the output** in whatever way you need, the `stylish` output is as good as it sounds, but if you need JSON or Checkstyle outputs to integrate with other tools, the lint command can output those too.
|
|
75
83
|
|
|
76
|
-
**Multiple files supported** so you don't need to bundle your API description to lint it, just
|
|
84
|
+
**Multiple files supported** so you don't need to bundle your API description to lint it, just point Redocly CLI at the "entry point" (e.g.: `openapi.yaml`) and it handles the rest.
|
|
77
85
|
|
|
78
86
|
[Learn more about API standards and configuring Redocly rules](https://redocly.com/docs/cli/api-standards).
|
|
79
87
|
|
|
@@ -63,6 +63,7 @@ export declare const bundleDocument: jest.Mock<Promise<{
|
|
|
63
63
|
}>, []>;
|
|
64
64
|
export declare const detectSpec: jest.Mock<any, any>;
|
|
65
65
|
export declare const isAbsoluteUrl: jest.Mock<any, any>;
|
|
66
|
+
export declare const stringifyYaml: jest.Mock<any, [data: any]>;
|
|
66
67
|
export declare class BaseResolver {
|
|
67
68
|
cache: Map<string, Promise<Document | ResolveError>>;
|
|
68
69
|
getFiles: jest.Mock<any, any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Oas3Operations = exports.SpecVersion = exports.YamlParseError = exports.ResolveError = exports.BaseResolver = exports.isAbsoluteUrl = exports.detectSpec = exports.bundleDocument = exports.doesYamlFileExist = exports.findConfig = exports.slash = exports.formatProblems = exports.getTotals = exports.bundle = exports.lint = exports.getMergedConfig = exports.loadConfig = exports.RedoclyClient = exports.__redoclyClient = void 0;
|
|
3
|
+
exports.Oas3Operations = exports.SpecVersion = exports.YamlParseError = exports.ResolveError = exports.BaseResolver = exports.stringifyYaml = exports.isAbsoluteUrl = exports.detectSpec = exports.bundleDocument = 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
|
const documents_1 = require("../documents");
|
|
6
6
|
exports.__redoclyClient = {
|
|
@@ -30,6 +30,7 @@ exports.doesYamlFileExist = jest.fn();
|
|
|
30
30
|
exports.bundleDocument = jest.fn(() => Promise.resolve({ problems: {} }));
|
|
31
31
|
exports.detectSpec = jest.fn();
|
|
32
32
|
exports.isAbsoluteUrl = jest.fn();
|
|
33
|
+
exports.stringifyYaml = jest.fn((data) => data);
|
|
33
34
|
class BaseResolver {
|
|
34
35
|
constructor() {
|
|
35
36
|
this.cache = new Map();
|
|
@@ -66,7 +67,7 @@ var SpecVersion;
|
|
|
66
67
|
SpecVersion["OAS3_0"] = "oas3_0";
|
|
67
68
|
SpecVersion["OAS3_1"] = "oas3_1";
|
|
68
69
|
SpecVersion["Async2"] = "async2";
|
|
69
|
-
})(SpecVersion
|
|
70
|
+
})(SpecVersion || (exports.SpecVersion = SpecVersion = {}));
|
|
70
71
|
var Oas3Operations;
|
|
71
72
|
(function (Oas3Operations) {
|
|
72
73
|
Oas3Operations["get"] = "get";
|
|
@@ -77,4 +78,4 @@ var Oas3Operations;
|
|
|
77
78
|
Oas3Operations["head"] = "head";
|
|
78
79
|
Oas3Operations["patch"] = "patch";
|
|
79
80
|
Oas3Operations["trace"] = "trace";
|
|
80
|
-
})(Oas3Operations
|
|
81
|
+
})(Oas3Operations || (exports.Oas3Operations = Oas3Operations = {}));
|
package/lib/__mocks__/utils.d.ts
CHANGED
|
@@ -37,3 +37,5 @@ export declare const loadConfigAndHandleErrors: jest.Mock<{
|
|
|
37
37
|
}, []>;
|
|
38
38
|
export declare const checkIfRulesetExist: jest.Mock<any, any>;
|
|
39
39
|
export declare const sortTopLevelKeysForOas: jest.Mock<any, [document: any]>;
|
|
40
|
+
export declare const getAndValidateFileExtension: jest.Mock<string | undefined, [fileName: string]>;
|
|
41
|
+
export declare const writeToFileByExtension: jest.Mock<any, any>;
|
package/lib/__mocks__/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortTopLevelKeysForOas = exports.checkIfRulesetExist = exports.loadConfigAndHandleErrors = exports.writeYaml = exports.exitWithError = exports.handleError = exports.getOutputFileName = exports.printLintTotals = exports.printUnusedWarnings = exports.printExecutionTime = exports.getExecutionTime = exports.pluralize = exports.slash = exports.dumpBundle = exports.getFallbackApisOrExit = void 0;
|
|
3
|
+
exports.writeToFileByExtension = exports.getAndValidateFileExtension = exports.sortTopLevelKeysForOas = exports.checkIfRulesetExist = exports.loadConfigAndHandleErrors = exports.writeYaml = 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
4
|
const config_1 = require("../__tests__/fixtures/config");
|
|
5
5
|
exports.getFallbackApisOrExit = jest.fn((entrypoints) => entrypoints.map((path) => ({ path })));
|
|
6
6
|
exports.dumpBundle = jest.fn(() => '');
|
|
@@ -17,3 +17,5 @@ exports.writeYaml = jest.fn();
|
|
|
17
17
|
exports.loadConfigAndHandleErrors = jest.fn(() => config_1.ConfigFixture);
|
|
18
18
|
exports.checkIfRulesetExist = jest.fn();
|
|
19
19
|
exports.sortTopLevelKeysForOas = jest.fn((document) => document);
|
|
20
|
+
exports.getAndValidateFileExtension = jest.fn((fileName) => fileName.split('.').pop());
|
|
21
|
+
exports.writeToFileByExtension = jest.fn();
|
|
@@ -33,14 +33,14 @@ jest.mock('handlebars', () => ({
|
|
|
33
33
|
}));
|
|
34
34
|
describe('build-docs', () => {
|
|
35
35
|
it('should return correct html and call function for ssr', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
const result = yield utils_1.getPageHTML({}, '../some-path/openapi.yaml', Object.assign(Object.assign({}, config), { redocCurrentVersion: '2.0.0' }));
|
|
36
|
+
const result = yield (0, utils_1.getPageHTML)({}, '../some-path/openapi.yaml', Object.assign(Object.assign({}, config), { redocCurrentVersion: '2.0.0' }));
|
|
37
37
|
expect(server_1.renderToString).toBeCalledTimes(1);
|
|
38
38
|
expect(redoc_1.createStore).toBeCalledTimes(1);
|
|
39
39
|
expect(result).toBe('<html></html>');
|
|
40
40
|
}));
|
|
41
41
|
it('should work correctly when calling handlerBuildCommand', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
42
|
const processExitMock = jest.spyOn(process, 'exit').mockImplementation();
|
|
43
|
-
yield build_docs_1.handlerBuildCommand({
|
|
43
|
+
yield (0, build_docs_1.handlerBuildCommand)({
|
|
44
44
|
o: '',
|
|
45
45
|
title: 'test',
|
|
46
46
|
disableGoogleFont: false,
|
|
@@ -34,7 +34,7 @@ describe('bundle', () => {
|
|
|
34
34
|
});
|
|
35
35
|
it('bundles definitions w/o linting', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
36
|
const apis = ['foo.yaml', 'bar.yaml'];
|
|
37
|
-
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
37
|
+
yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
38
38
|
apis,
|
|
39
39
|
ext: 'yaml',
|
|
40
40
|
format: 'codeframe',
|
|
@@ -44,7 +44,7 @@ describe('bundle', () => {
|
|
|
44
44
|
}));
|
|
45
45
|
it('exits with code 0 when bundles definitions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
46
|
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
47
|
-
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
47
|
+
yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
48
48
|
apis,
|
|
49
49
|
ext: 'yaml',
|
|
50
50
|
format: 'codeframe',
|
|
@@ -59,7 +59,7 @@ describe('bundle', () => {
|
|
|
59
59
|
warnings: 0,
|
|
60
60
|
ignored: 0,
|
|
61
61
|
});
|
|
62
|
-
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
62
|
+
yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
63
63
|
apis,
|
|
64
64
|
ext: 'yaml',
|
|
65
65
|
format: 'codeframe',
|
|
@@ -70,7 +70,7 @@ describe('bundle', () => {
|
|
|
70
70
|
}));
|
|
71
71
|
it('exits with code 0 when bundles definitions w/linting w/o errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
72
|
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
73
|
-
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
73
|
+
yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
74
74
|
apis,
|
|
75
75
|
ext: 'yaml',
|
|
76
76
|
format: 'codeframe',
|
|
@@ -86,7 +86,7 @@ describe('bundle', () => {
|
|
|
86
86
|
warnings: 0,
|
|
87
87
|
ignored: 0,
|
|
88
88
|
});
|
|
89
|
-
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
89
|
+
yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
90
90
|
apis,
|
|
91
91
|
ext: 'yaml',
|
|
92
92
|
format: 'codeframe',
|
|
@@ -101,7 +101,7 @@ describe('bundle', () => {
|
|
|
101
101
|
openapi_core_1.bundle.mockImplementationOnce(() => {
|
|
102
102
|
throw new Error('Invalid definition');
|
|
103
103
|
});
|
|
104
|
-
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
104
|
+
yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
105
105
|
apis,
|
|
106
106
|
ext: 'json',
|
|
107
107
|
format: 'codeframe',
|
|
@@ -117,7 +117,7 @@ describe('bundle', () => {
|
|
|
117
117
|
warnings: 0,
|
|
118
118
|
ignored: 0,
|
|
119
119
|
});
|
|
120
|
-
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
120
|
+
yield (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
121
121
|
apis,
|
|
122
122
|
ext: 'yaml',
|
|
123
123
|
format: 'codeframe',
|
|
@@ -21,11 +21,11 @@ describe('handleJoin fails', () => {
|
|
|
21
21
|
const colloreteYellowMock = colorette_1.yellow;
|
|
22
22
|
colloreteYellowMock.mockImplementation((string) => string);
|
|
23
23
|
it('should call exitWithError because only one entrypoint', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
yield join_1.handleJoin({ apis: ['first.yaml'] }, {}, 'cli-version');
|
|
24
|
+
yield (0, join_1.handleJoin)({ apis: ['first.yaml'] }, {}, 'cli-version');
|
|
25
25
|
expect(utils_1.exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided. \n\n`);
|
|
26
26
|
}));
|
|
27
27
|
it('should call exitWithError because passed all 3 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
yield join_1.handleJoin({
|
|
28
|
+
yield (0, join_1.handleJoin)({
|
|
29
29
|
apis: ['first.yaml', 'second.yaml'],
|
|
30
30
|
'prefix-tags-with-info-prop': 'something',
|
|
31
31
|
'without-x-tag-groups': true,
|
|
@@ -34,7 +34,7 @@ describe('handleJoin fails', () => {
|
|
|
34
34
|
expect(utils_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, prefix-tags-with-info-prop, without-x-tag-groups together.\nPlease choose only one! \n\n`);
|
|
35
35
|
}));
|
|
36
36
|
it('should call exitWithError because passed all 2 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
yield join_1.handleJoin({
|
|
37
|
+
yield (0, join_1.handleJoin)({
|
|
38
38
|
apis: ['first.yaml', 'second.yaml'],
|
|
39
39
|
'without-x-tag-groups': true,
|
|
40
40
|
'prefix-tags-with-filename': true,
|
|
@@ -42,7 +42,7 @@ describe('handleJoin fails', () => {
|
|
|
42
42
|
expect(utils_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, without-x-tag-groups together.\nPlease choose only one! \n\n`);
|
|
43
43
|
}));
|
|
44
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 join_1.handleJoin({
|
|
45
|
+
yield (0, join_1.handleJoin)({
|
|
46
46
|
apis: ['first.yaml', 'second.yaml'],
|
|
47
47
|
}, config_1.ConfigFixture, 'cli-version');
|
|
48
48
|
expect(utils_1.exitWithError).toHaveBeenCalledWith('Only OpenAPI 3.0 and OpenAPI 3.1 are supported: undefined \n\n');
|
|
@@ -51,50 +51,57 @@ describe('handleJoin fails', () => {
|
|
|
51
51
|
openapi_core_1.detectSpec
|
|
52
52
|
.mockImplementationOnce(() => 'oas3_0')
|
|
53
53
|
.mockImplementationOnce(() => 'oas3_1');
|
|
54
|
-
yield join_1.handleJoin({
|
|
54
|
+
yield (0, join_1.handleJoin)({
|
|
55
55
|
apis: ['first.yaml', 'second.yaml'],
|
|
56
56
|
}, config_1.ConfigFixture, 'cli-version');
|
|
57
57
|
expect(utils_1.exitWithError).toHaveBeenCalledWith('All APIs must use the same OpenAPI version: undefined \n\n');
|
|
58
58
|
}));
|
|
59
|
-
it('should call
|
|
59
|
+
it('should call writeToFileByExtension function', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
60
|
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
61
|
-
yield join_1.handleJoin({
|
|
61
|
+
yield (0, join_1.handleJoin)({
|
|
62
62
|
apis: ['first.yaml', 'second.yaml'],
|
|
63
63
|
}, config_1.ConfigFixture, 'cli-version');
|
|
64
|
-
expect(utils_1.
|
|
64
|
+
expect(utils_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
|
|
65
65
|
}));
|
|
66
|
-
it('should call
|
|
66
|
+
it('should call writeToFileByExtension function for OpenAPI 3.1', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
67
|
openapi_core_1.detectSpec.mockReturnValue('oas3_1');
|
|
68
|
-
yield join_1.handleJoin({
|
|
68
|
+
yield (0, join_1.handleJoin)({
|
|
69
69
|
apis: ['first.yaml', 'second.yaml'],
|
|
70
70
|
}, config_1.ConfigFixture, 'cli-version');
|
|
71
|
-
expect(utils_1.
|
|
71
|
+
expect(utils_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
|
|
72
72
|
}));
|
|
73
|
-
it('should call
|
|
73
|
+
it('should call writeToFileByExtension function with custom output file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
74
|
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
75
|
-
yield join_1.handleJoin({
|
|
75
|
+
yield (0, join_1.handleJoin)({
|
|
76
76
|
apis: ['first.yaml', 'second.yaml'],
|
|
77
77
|
output: 'output.yml',
|
|
78
78
|
}, config_1.ConfigFixture, 'cli-version');
|
|
79
|
-
expect(utils_1.
|
|
79
|
+
expect(utils_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* () {
|
|
82
|
+
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');
|
|
86
|
+
expect(utils_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.json', expect.any(Boolean));
|
|
80
87
|
}));
|
|
81
88
|
it('should call skipDecorators and skipPreprocessors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
89
|
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
83
|
-
yield join_1.handleJoin({
|
|
90
|
+
yield (0, join_1.handleJoin)({
|
|
84
91
|
apis: ['first.yaml', 'second.yaml'],
|
|
85
92
|
}, config_1.ConfigFixture, 'cli-version');
|
|
86
|
-
const config = openapi_core_2.loadConfig();
|
|
93
|
+
const config = (0, openapi_core_2.loadConfig)();
|
|
87
94
|
expect(config.styleguide.skipDecorators).toHaveBeenCalled();
|
|
88
95
|
expect(config.styleguide.skipPreprocessors).toHaveBeenCalled();
|
|
89
96
|
}));
|
|
90
97
|
it('should not call skipDecorators and skipPreprocessors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
98
|
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
92
|
-
yield join_1.handleJoin({
|
|
99
|
+
yield (0, join_1.handleJoin)({
|
|
93
100
|
apis: ['first.yaml', 'second.yaml'],
|
|
94
101
|
decorate: true,
|
|
95
102
|
preprocess: true,
|
|
96
103
|
}, config_1.ConfigFixture, 'cli-version');
|
|
97
|
-
const config = openapi_core_2.loadConfig();
|
|
104
|
+
const config = (0, openapi_core_2.loadConfig)();
|
|
98
105
|
expect(config.styleguide.skipDecorators).not.toHaveBeenCalled();
|
|
99
106
|
expect(config.styleguide.skipPreprocessors).not.toHaveBeenCalled();
|
|
100
107
|
}));
|
|
@@ -47,11 +47,11 @@ describe('handleLint', () => {
|
|
|
47
47
|
});
|
|
48
48
|
describe('loadConfig and getEnrtypoints stage', () => {
|
|
49
49
|
it('should fail if config file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'config.yaml' }));
|
|
50
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'config.yaml' }));
|
|
51
51
|
expect(utils_1.exitWithError).toHaveBeenCalledWith('Please, provide valid path to the configuration file');
|
|
52
52
|
}));
|
|
53
53
|
it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
54
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
55
55
|
expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
|
|
56
56
|
configPath: undefined,
|
|
57
57
|
customExtends: undefined,
|
|
@@ -60,7 +60,7 @@ describe('handleLint', () => {
|
|
|
60
60
|
expect(utils_1.getFallbackApisOrExit).toHaveBeenCalled();
|
|
61
61
|
}));
|
|
62
62
|
it('should call loadConfig with args if such exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'redocly.yaml', extends: ['some/path'] }));
|
|
63
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'redocly.yaml', extends: ['some/path'] }));
|
|
64
64
|
expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
|
|
65
65
|
configPath: 'redocly.yaml',
|
|
66
66
|
customExtends: ['some/path'],
|
|
@@ -68,35 +68,35 @@ describe('handleLint', () => {
|
|
|
68
68
|
});
|
|
69
69
|
}));
|
|
70
70
|
it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'generate-ignore-file': true }));
|
|
71
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'generate-ignore-file': true }));
|
|
72
72
|
expect(getMergedConfigMock).toHaveBeenCalled();
|
|
73
73
|
}));
|
|
74
74
|
it('should check if ruleset exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
75
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
76
76
|
expect(utils_1.checkIfRulesetExist).toHaveBeenCalledTimes(1);
|
|
77
77
|
}));
|
|
78
78
|
it('should fail if apis not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { apis: [] }));
|
|
79
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { apis: [] }));
|
|
80
80
|
expect(utils_1.getFallbackApisOrExit).toHaveBeenCalledTimes(1);
|
|
81
81
|
expect(utils_1.exitWithError).toHaveBeenCalledWith('No APIs were provided');
|
|
82
82
|
}));
|
|
83
83
|
});
|
|
84
84
|
describe('loop through entrypoints and lint stage', () => {
|
|
85
85
|
it('should call getMergedConfig and lint ', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
86
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
87
87
|
expect(perf_hooks_1.performance.now).toHaveBeenCalled();
|
|
88
88
|
expect(getMergedConfigMock).toHaveBeenCalled();
|
|
89
89
|
expect(openapi_core_1.lint).toHaveBeenCalled();
|
|
90
90
|
}));
|
|
91
91
|
it('should call skipRules,skipPreprocessors and addIgnore with argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
92
|
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
93
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'skip-preprocessor': ['preprocessor'], 'skip-rule': ['rule'], 'generate-ignore-file': true }));
|
|
93
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'skip-preprocessor': ['preprocessor'], 'skip-rule': ['rule'], 'generate-ignore-file': true }));
|
|
94
94
|
expect(config_1.ConfigFixture.styleguide.skipRules).toHaveBeenCalledWith(['rule']);
|
|
95
95
|
expect(config_1.ConfigFixture.styleguide.skipPreprocessors).toHaveBeenCalledWith(['preprocessor']);
|
|
96
96
|
}));
|
|
97
97
|
it('should call formatProblems and getExecutionTime with argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
98
|
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
99
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'max-problems': 2, format: 'stylish' }));
|
|
99
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, 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',
|
|
@@ -108,26 +108,26 @@ describe('handleLint', () => {
|
|
|
108
108
|
}));
|
|
109
109
|
it('should catch error in handleError if something fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
110
|
openapi_core_1.lint.mockRejectedValueOnce('error');
|
|
111
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
111
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
112
112
|
expect(utils_1.handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
|
|
113
113
|
}));
|
|
114
114
|
});
|
|
115
115
|
describe('erros and warning handle after lint stage', () => {
|
|
116
116
|
it('should call printLintTotals and printLintTotals', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
117
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
118
118
|
expect(utils_1.printUnusedWarnings).toHaveBeenCalled();
|
|
119
119
|
}));
|
|
120
120
|
it('should call exit with 0 if no errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
121
|
utils_1.loadConfigAndHandleErrors.mockImplementation(() => {
|
|
122
122
|
return Object.assign({}, config_1.ConfigFixture);
|
|
123
123
|
});
|
|
124
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
124
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
125
125
|
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
126
126
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
127
127
|
}));
|
|
128
128
|
it('should exit with 1 if total errors > 0', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
129
|
openapi_core_1.getTotals.mockReturnValueOnce({ errors: 1 });
|
|
130
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
130
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
131
131
|
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
132
132
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
133
133
|
}));
|
|
@@ -142,8 +142,8 @@ describe('handleLint', () => {
|
|
|
142
142
|
},
|
|
143
143
|
};
|
|
144
144
|
});
|
|
145
|
-
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
146
|
-
expect(process.stderr.write).toHaveBeenCalledWith(`No configurations were provided -- using built in ${colorette_1.blue('recommended')} configuration by default.\n\n`);
|
|
145
|
+
yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
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
|
});
|
|
@@ -33,7 +33,7 @@ describe('push-with-region', () => {
|
|
|
33
33
|
});
|
|
34
34
|
it('should call login with default domain when region is US', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
redoclyClient.domain = 'redoc.ly';
|
|
36
|
-
yield push_1.handlePush({
|
|
36
|
+
yield (0, push_1.handlePush)({
|
|
37
37
|
upsert: true,
|
|
38
38
|
api: 'spec.json',
|
|
39
39
|
destination: '@org/my-api@1.0.0',
|
|
@@ -44,7 +44,7 @@ describe('push-with-region', () => {
|
|
|
44
44
|
}));
|
|
45
45
|
it('should call login with EU domain when region is EU', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
46
|
redoclyClient.domain = 'eu.redocly.com';
|
|
47
|
-
yield push_1.handlePush({
|
|
47
|
+
yield (0, push_1.handlePush)({
|
|
48
48
|
upsert: true,
|
|
49
49
|
api: 'spec.json',
|
|
50
50
|
destination: '@org/my-api@1.0.0',
|