@redocly/cli 1.34.3 → 2.0.0-next.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/README.md +34 -3
- package/bin/cli.js +1 -1
- package/lib/auth/device-flow.d.ts +1 -0
- package/lib/auth/device-flow.d.ts.map +1 -0
- package/lib/auth/device-flow.js +15 -17
- package/lib/auth/device-flow.js.map +1 -0
- package/lib/auth/oauth-client.d.ts +1 -0
- package/lib/auth/oauth-client.d.ts.map +1 -0
- package/lib/auth/oauth-client.js +21 -23
- package/lib/auth/oauth-client.js.map +1 -0
- package/lib/commands/auth.d.ts +3 -5
- package/lib/commands/auth.d.ts.map +1 -0
- package/lib/commands/auth.js +19 -44
- package/lib/commands/auth.js.map +1 -0
- package/lib/commands/build-docs/index.d.ts +4 -3
- package/lib/commands/build-docs/index.d.ts.map +1 -0
- package/lib/commands/build-docs/index.js +23 -24
- package/lib/commands/build-docs/index.js.map +1 -0
- package/lib/commands/build-docs/types.d.ts +2 -1
- package/lib/commands/build-docs/types.d.ts.map +1 -0
- package/lib/commands/build-docs/types.js +2 -2
- package/lib/commands/build-docs/types.js.map +1 -0
- package/lib/commands/build-docs/utils.d.ts +3 -2
- package/lib/commands/build-docs/utils.d.ts.map +1 -0
- package/lib/commands/build-docs/utils.js +35 -37
- package/lib/commands/build-docs/utils.js.map +1 -0
- package/lib/commands/bundle.d.ts +6 -3
- package/lib/commands/bundle.d.ts.map +1 -0
- package/lib/commands/bundle.js +34 -38
- package/lib/commands/bundle.js.map +1 -0
- package/lib/commands/eject.d.ts +3 -2
- package/lib/commands/eject.d.ts.map +1 -0
- package/lib/commands/eject.js +11 -13
- package/lib/commands/eject.js.map +1 -0
- package/lib/commands/join.d.ts +4 -3
- package/lib/commands/join.d.ts.map +1 -0
- package/lib/commands/join.js +79 -81
- package/lib/commands/join.js.map +1 -0
- package/lib/commands/lint.d.ts +8 -6
- package/lib/commands/lint.d.ts.map +1 -0
- package/lib/commands/lint.js +53 -62
- package/lib/commands/lint.js.map +1 -0
- package/lib/commands/preview-project/constants.d.ts +2 -1
- package/lib/commands/preview-project/constants.d.ts.map +1 -0
- package/lib/commands/preview-project/constants.js +4 -6
- package/lib/commands/preview-project/constants.js.map +1 -0
- package/lib/commands/preview-project/index.d.ts +3 -2
- package/lib/commands/preview-project/index.d.ts.map +1 -0
- package/lib/commands/preview-project/index.js +21 -23
- package/lib/commands/preview-project/index.js.map +1 -0
- package/lib/commands/preview-project/types.d.ts +3 -2
- package/lib/commands/preview-project/types.d.ts.map +1 -0
- package/lib/commands/preview-project/types.js +2 -2
- package/lib/commands/preview-project/types.js.map +1 -0
- package/lib/commands/split/index.d.ts +4 -3
- package/lib/commands/split/index.d.ts.map +1 -0
- package/lib/commands/split/index.js +53 -57
- package/lib/commands/split/index.js.map +1 -0
- package/lib/commands/split/types.d.ts +2 -2
- package/lib/commands/split/types.d.ts.map +1 -0
- package/lib/commands/split/types.js +11 -13
- package/lib/commands/split/types.js.map +1 -0
- package/lib/commands/stats.d.ts +3 -2
- package/lib/commands/stats.d.ts.map +1 -0
- package/lib/commands/stats.js +21 -24
- package/lib/commands/stats.js.map +1 -0
- package/lib/commands/translations.d.ts +3 -2
- package/lib/commands/translations.d.ts.map +1 -0
- package/lib/commands/translations.js +11 -13
- package/lib/commands/translations.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +109 -239
- package/lib/index.js.map +1 -0
- package/lib/otel.d.ts +2 -1
- package/lib/otel.d.ts.map +1 -0
- package/lib/otel.js +22 -23
- package/lib/otel.js.map +1 -0
- package/lib/reunite/api/api-client.d.ts +4 -3
- package/lib/reunite/api/api-client.d.ts.map +1 -0
- package/lib/reunite/api/api-client.js +14 -20
- package/lib/reunite/api/api-client.js.map +1 -0
- package/lib/reunite/api/api-keys.d.ts +2 -1
- package/lib/reunite/api/api-keys.d.ts.map +1 -0
- package/lib/reunite/api/api-keys.js +4 -20
- package/lib/reunite/api/api-keys.js.map +1 -0
- package/lib/reunite/api/domains.d.ts +5 -2
- package/lib/reunite/api/domains.d.ts.map +1 -0
- package/lib/reunite/api/domains.js +6 -15
- package/lib/reunite/api/domains.js.map +1 -0
- package/lib/reunite/api/index.d.ts +4 -3
- package/lib/reunite/api/index.d.ts.map +1 -0
- package/lib/reunite/api/index.js +4 -19
- package/lib/reunite/api/index.js.map +1 -0
- package/lib/reunite/api/types.d.ts +1 -0
- package/lib/reunite/api/types.d.ts.map +1 -0
- package/lib/reunite/api/types.js +2 -2
- package/lib/reunite/api/types.js.map +1 -0
- package/lib/reunite/commands/push-status.d.ts +6 -5
- package/lib/reunite/commands/push-status.d.ts.map +1 -0
- package/lib/reunite/commands/push-status.js +31 -37
- package/lib/reunite/commands/push-status.js.map +1 -0
- package/lib/reunite/commands/push.d.ts +6 -6
- package/lib/reunite/commands/push.d.ts.map +1 -0
- package/lib/reunite/commands/push.js +31 -40
- package/lib/reunite/commands/push.js.map +1 -0
- package/lib/reunite/commands/utils.d.ts +4 -3
- package/lib/reunite/commands/utils.d.ts.map +1 -0
- package/lib/reunite/commands/utils.js +9 -12
- package/lib/reunite/commands/utils.js.map +1 -0
- package/lib/reunite/utils.d.ts +1 -0
- package/lib/reunite/utils.d.ts.map +1 -0
- package/lib/reunite/utils.js +2 -5
- package/lib/reunite/utils.js.map +1 -0
- package/lib/types.d.ts +15 -27
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -5
- package/lib/types.js.map +1 -0
- package/lib/utils/assert-node-version.d.ts +1 -0
- package/lib/utils/assert-node-version.d.ts.map +1 -0
- package/lib/utils/assert-node-version.js +8 -10
- package/lib/utils/assert-node-version.js.map +1 -0
- package/lib/utils/error.d.ts +4 -0
- package/lib/utils/error.d.ts.map +1 -0
- package/lib/utils/error.js +8 -0
- package/lib/utils/error.js.map +1 -0
- package/lib/utils/fetch-with-timeout.d.ts +1 -0
- package/lib/utils/fetch-with-timeout.d.ts.map +1 -0
- package/lib/utils/fetch-with-timeout.js +6 -8
- package/lib/utils/fetch-with-timeout.js.map +1 -0
- package/lib/utils/{getCommandNameFromArgs.d.ts → get-command-name-from-args.d.ts} +1 -0
- package/lib/utils/get-command-name-from-args.d.ts.map +1 -0
- package/lib/utils/get-command-name-from-args.js +4 -0
- package/lib/utils/get-command-name-from-args.js.map +1 -0
- package/lib/utils/js-utils.d.ts +1 -0
- package/lib/utils/js-utils.d.ts.map +1 -0
- package/lib/utils/js-utils.js +8 -12
- package/lib/utils/js-utils.js.map +1 -0
- package/lib/utils/miscellaneous.d.ts +9 -48
- package/lib/utils/miscellaneous.d.ts.map +1 -0
- package/lib/utils/miscellaneous.js +131 -269
- package/lib/utils/miscellaneous.js.map +1 -0
- package/lib/utils/package.d.ts +2 -0
- package/lib/utils/package.d.ts.map +1 -0
- package/lib/utils/package.js +4 -0
- package/lib/utils/package.js.map +1 -0
- package/lib/utils/platform.d.ts +1 -0
- package/lib/utils/platform.d.ts.map +1 -0
- package/lib/utils/platform.js +5 -9
- package/lib/utils/platform.js.map +1 -0
- package/lib/utils/proxy-agent.d.ts +3 -0
- package/lib/utils/proxy-agent.d.ts.map +1 -0
- package/lib/utils/proxy-agent.js +6 -0
- package/lib/utils/proxy-agent.js.map +1 -0
- package/lib/utils/spinner.d.ts +1 -0
- package/lib/utils/spinner.d.ts.map +1 -0
- package/lib/utils/spinner.js +8 -10
- package/lib/utils/spinner.js.map +1 -0
- package/lib/utils/telemetry.d.ts +40 -0
- package/lib/utils/telemetry.d.ts.map +1 -0
- package/lib/utils/telemetry.js +138 -0
- package/lib/utils/telemetry.js.map +1 -0
- package/lib/utils/update-version-notifier.d.ts +1 -1
- package/lib/utils/update-version-notifier.d.ts.map +1 -0
- package/lib/utils/update-version-notifier.js +35 -38
- package/lib/utils/update-version-notifier.js.map +1 -0
- package/lib/utils/validate-positive-number.d.ts +2 -0
- package/lib/utils/validate-positive-number.d.ts.map +1 -0
- package/lib/utils/validate-positive-number.js +13 -0
- package/lib/utils/validate-positive-number.js.map +1 -0
- package/lib/wrapper.d.ts +3 -3
- package/lib/wrapper.d.ts.map +1 -0
- package/lib/wrapper.js +39 -26
- package/lib/wrapper.js.map +1 -0
- package/package.json +15 -16
- package/CHANGELOG.md +0 -770
- package/lib/__mocks__/@redocly/openapi-core.d.ts +0 -99
- package/lib/__mocks__/@redocly/openapi-core.js +0 -84
- package/lib/__mocks__/documents.d.ts +0 -150
- package/lib/__mocks__/documents.js +0 -123
- package/lib/__mocks__/fs.d.ts +0 -8
- package/lib/__mocks__/fs.js +0 -9
- package/lib/__mocks__/perf_hooks.d.ts +0 -3
- package/lib/__mocks__/perf_hooks.js +0 -6
- package/lib/__mocks__/redoc.d.ts +0 -6
- package/lib/__mocks__/redoc.js +0 -5
- package/lib/__tests__/commands/build-docs.test.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +0 -54
- package/lib/__tests__/commands/bundle.test.d.ts +0 -1
- package/lib/__tests__/commands/bundle.test.js +0 -235
- package/lib/__tests__/commands/join.test.d.ts +0 -1
- package/lib/__tests__/commands/join.test.js +0 -274
- package/lib/__tests__/commands/lint.test.d.ts +0 -1
- package/lib/__tests__/commands/lint.test.js +0 -149
- package/lib/__tests__/commands/push-region.test.d.ts +0 -1
- package/lib/__tests__/commands/push-region.test.js +0 -90
- package/lib/__tests__/commands/push.test.d.ts +0 -1
- package/lib/__tests__/commands/push.test.js +0 -496
- package/lib/__tests__/fetch-with-timeout.test.d.ts +0 -1
- package/lib/__tests__/fetch-with-timeout.test.js +0 -64
- package/lib/__tests__/fixtures/config.d.ts +0 -21
- package/lib/__tests__/fixtures/config.js +0 -24
- package/lib/__tests__/spinner.test.d.ts +0 -1
- package/lib/__tests__/spinner.test.js +0 -43
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -651
- package/lib/__tests__/wrapper.test.d.ts +0 -1
- package/lib/__tests__/wrapper.test.js +0 -76
- package/lib/auth/__tests__/device-flow.test.d.ts +0 -1
- package/lib/auth/__tests__/device-flow.test.js +0 -62
- package/lib/auth/__tests__/oauth-client.test.d.ts +0 -1
- package/lib/auth/__tests__/oauth-client.test.js +0 -93
- package/lib/commands/preview-docs/index.d.ts +0 -12
- package/lib/commands/preview-docs/index.js +0 -127
- package/lib/commands/preview-docs/preview-server/default.hbs +0 -24
- package/lib/commands/preview-docs/preview-server/hot.js +0 -59
- package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/lib/commands/preview-docs/preview-server/preview-server.d.ts +0 -5
- package/lib/commands/preview-docs/preview-server/preview-server.js +0 -113
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -22
- package/lib/commands/preview-docs/preview-server/server.js +0 -85
- package/lib/commands/push.d.ts +0 -44
- package/lib/commands/push.js +0 -301
- package/lib/commands/split/__tests__/index.test.d.ts +0 -1
- package/lib/commands/split/__tests__/index.test.js +0 -91
- package/lib/reunite/api/__tests__/api-keys.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api-keys.test.js +0 -26
- package/lib/reunite/api/__tests__/api.client.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api.client.test.js +0 -337
- package/lib/reunite/api/__tests__/domains.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/domains.test.js +0 -32
- package/lib/reunite/commands/__tests__/push-status.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push-status.test.js +0 -563
- package/lib/reunite/commands/__tests__/push.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push.test.js +0 -315
- package/lib/reunite/commands/__tests__/utils.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/utils.test.js +0 -51
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -43
- package/lib/utils/__mocks__/miscellaneous.js +0 -24
- package/lib/utils/getCommandNameFromArgs.js +0 -6
- package/src/__mocks__/@redocly/openapi-core.ts +0 -88
- package/src/__mocks__/documents.ts +0 -124
- package/src/__mocks__/fs.ts +0 -6
- package/src/__mocks__/perf_hooks.ts +0 -3
- package/src/__mocks__/redoc.ts +0 -2
- package/src/__tests__/commands/build-docs.test.ts +0 -59
- package/src/__tests__/commands/bundle.test.ts +0 -285
- package/src/__tests__/commands/join.test.ts +0 -334
- package/src/__tests__/commands/lint.test.ts +0 -190
- package/src/__tests__/commands/push-region.test.ts +0 -104
- package/src/__tests__/commands/push.test.ts +0 -553
- package/src/__tests__/fetch-with-timeout.test.ts +0 -81
- package/src/__tests__/fixtures/config.ts +0 -21
- package/src/__tests__/fixtures/openapi.json +0 -0
- package/src/__tests__/fixtures/openapi.yaml +0 -0
- package/src/__tests__/fixtures/redocly.yaml +0 -0
- package/src/__tests__/spinner.test.ts +0 -51
- package/src/__tests__/utils.test.ts +0 -781
- package/src/__tests__/wrapper.test.ts +0 -91
- package/src/auth/__tests__/device-flow.test.ts +0 -73
- package/src/auth/__tests__/oauth-client.test.ts +0 -117
- package/src/auth/device-flow.ts +0 -175
- package/src/auth/oauth-client.ts +0 -111
- package/src/commands/auth.ts +0 -66
- package/src/commands/build-docs/index.ts +0 -55
- package/src/commands/build-docs/template.hbs +0 -23
- package/src/commands/build-docs/types.ts +0 -25
- package/src/commands/build-docs/utils.ts +0 -110
- package/src/commands/bundle.ts +0 -154
- package/src/commands/eject.ts +0 -42
- package/src/commands/join.ts +0 -794
- package/src/commands/lint.ts +0 -169
- package/src/commands/preview-docs/index.ts +0 -183
- package/src/commands/preview-docs/preview-server/default.hbs +0 -24
- package/src/commands/preview-docs/preview-server/hot.js +0 -59
- package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/src/commands/preview-docs/preview-server/preview-server.ts +0 -159
- package/src/commands/preview-docs/preview-server/server.ts +0 -92
- package/src/commands/preview-project/constants.ts +0 -23
- package/src/commands/preview-project/index.ts +0 -71
- package/src/commands/preview-project/types.ts +0 -12
- package/src/commands/push.ts +0 -470
- package/src/commands/split/__tests__/fixtures/samples.json +0 -61
- package/src/commands/split/__tests__/fixtures/spec.json +0 -70
- package/src/commands/split/__tests__/fixtures/webhooks.json +0 -85
- package/src/commands/split/__tests__/index.test.ts +0 -156
- package/src/commands/split/index.ts +0 -397
- package/src/commands/split/types.ts +0 -60
- package/src/commands/stats.ts +0 -140
- package/src/commands/translations.ts +0 -32
- package/src/custom.d.ts +0 -1
- package/src/index.ts +0 -970
- package/src/otel.ts +0 -59
- package/src/reunite/api/__tests__/api-keys.test.ts +0 -37
- package/src/reunite/api/__tests__/api.client.test.ts +0 -452
- package/src/reunite/api/__tests__/domains.test.ts +0 -41
- package/src/reunite/api/api-client.ts +0 -381
- package/src/reunite/api/api-keys.ts +0 -26
- package/src/reunite/api/domains.ts +0 -23
- package/src/reunite/api/index.ts +0 -3
- package/src/reunite/api/types.ts +0 -108
- package/src/reunite/commands/__tests__/push-status.test.ts +0 -653
- package/src/reunite/commands/__tests__/push.test.ts +0 -385
- package/src/reunite/commands/__tests__/utils.test.ts +0 -62
- package/src/reunite/commands/push-status.ts +0 -325
- package/src/reunite/commands/push.ts +0 -235
- package/src/reunite/commands/utils.ts +0 -66
- package/src/reunite/utils.ts +0 -1
- package/src/types.ts +0 -64
- package/src/utils/__mocks__/miscellaneous.ts +0 -24
- package/src/utils/assert-node-version.ts +0 -19
- package/src/utils/fetch-with-timeout.ts +0 -30
- package/src/utils/getCommandNameFromArgs.ts +0 -5
- package/src/utils/js-utils.ts +0 -24
- package/src/utils/miscellaneous.ts +0 -729
- package/src/utils/platform.ts +0 -31
- package/src/utils/spinner.ts +0 -50
- package/src/utils/update-version-notifier.ts +0 -115
- package/src/wrapper.ts +0 -77
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,781 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getFallbackApisOrExit,
|
|
3
|
-
isSubdir,
|
|
4
|
-
pathToFilename,
|
|
5
|
-
printConfigLintTotals,
|
|
6
|
-
langToExt,
|
|
7
|
-
checkIfRulesetExist,
|
|
8
|
-
handleError,
|
|
9
|
-
CircularJSONNotSupportedError,
|
|
10
|
-
sortTopLevelKeysForOas,
|
|
11
|
-
cleanColors,
|
|
12
|
-
HandledError,
|
|
13
|
-
cleanArgs,
|
|
14
|
-
getAndValidateFileExtension,
|
|
15
|
-
writeToFileByExtension,
|
|
16
|
-
} from '../utils/miscellaneous';
|
|
17
|
-
import { sanitizeLocale, sanitizePath, getPlatformSpawnArgs } from '../utils/platform';
|
|
18
|
-
import {
|
|
19
|
-
ResolvedApi,
|
|
20
|
-
Totals,
|
|
21
|
-
isAbsoluteUrl,
|
|
22
|
-
ResolveError,
|
|
23
|
-
YamlParseError,
|
|
24
|
-
stringifyYaml,
|
|
25
|
-
} from '@redocly/openapi-core';
|
|
26
|
-
import { blue, red, yellow } from 'colorette';
|
|
27
|
-
import { existsSync, statSync } from 'fs';
|
|
28
|
-
import * as path from 'path';
|
|
29
|
-
import * as process from 'process';
|
|
30
|
-
|
|
31
|
-
jest.mock('os');
|
|
32
|
-
jest.mock('colorette');
|
|
33
|
-
|
|
34
|
-
jest.mock('fs');
|
|
35
|
-
|
|
36
|
-
describe('isSubdir', () => {
|
|
37
|
-
it('can correctly determine if subdir', () => {
|
|
38
|
-
(
|
|
39
|
-
[
|
|
40
|
-
['/foo', '/foo', false],
|
|
41
|
-
['/foo', '/bar', false],
|
|
42
|
-
['/foo', '/foobar', false],
|
|
43
|
-
['/foo', '/foo/bar', true],
|
|
44
|
-
['/foo', '/foo/../bar', false],
|
|
45
|
-
['/foo', '/foo/./bar', true],
|
|
46
|
-
['/bar/../foo', '/foo/bar', true],
|
|
47
|
-
['/foo', './bar', false],
|
|
48
|
-
['/foo', '/foo/..bar', true],
|
|
49
|
-
] as [string, string, boolean][]
|
|
50
|
-
).forEach(([parent, child, expectRes]) => {
|
|
51
|
-
expect(isSubdir(parent, child)).toBe(expectRes);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('can correctly determine if subdir for windows-based paths', () => {
|
|
56
|
-
const os = require('os');
|
|
57
|
-
os.platform.mockImplementation(() => 'win32');
|
|
58
|
-
|
|
59
|
-
(
|
|
60
|
-
[
|
|
61
|
-
['C:/Foo', 'C:/Foo/Bar', true],
|
|
62
|
-
['C:\\Foo', 'C:\\Bar', false],
|
|
63
|
-
['C:\\Foo', 'D:\\Foo\\Bar', false],
|
|
64
|
-
] as [string, string, boolean][]
|
|
65
|
-
).forEach(([parent, child, expectRes]) => {
|
|
66
|
-
expect(isSubdir(parent, child)).toBe(expectRes);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
afterEach(() => {
|
|
71
|
-
jest.resetModules();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('pathToFilename', () => {
|
|
76
|
-
it('should use correct path separator', () => {
|
|
77
|
-
const processedPath = pathToFilename('/user/createWithList', '_');
|
|
78
|
-
expect(processedPath).toEqual('user_createWithList');
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('printConfigLintTotals', () => {
|
|
83
|
-
const totalProblemsMock: Totals = {
|
|
84
|
-
errors: 1,
|
|
85
|
-
warnings: 0,
|
|
86
|
-
ignored: 0,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const redColoretteMocks = red as jest.Mock<any, any>;
|
|
90
|
-
const yellowColoretteMocks = yellow as jest.Mock<any, any>;
|
|
91
|
-
|
|
92
|
-
beforeEach(() => {
|
|
93
|
-
yellowColoretteMocks.mockImplementation((text: string) => text);
|
|
94
|
-
redColoretteMocks.mockImplementation((text: string) => text);
|
|
95
|
-
jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should print errors if such exist', () => {
|
|
99
|
-
printConfigLintTotals(totalProblemsMock);
|
|
100
|
-
expect(process.stderr.write).toHaveBeenCalledWith('❌ Your config has 1 error.');
|
|
101
|
-
expect(redColoretteMocks).toHaveBeenCalledWith('❌ Your config has 1 error.');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should print warnign if no error', () => {
|
|
105
|
-
printConfigLintTotals({ ...totalProblemsMock, errors: 0, warnings: 2 });
|
|
106
|
-
expect(process.stderr.write).toHaveBeenCalledWith('⚠️ Your config has 2 warnings.\n');
|
|
107
|
-
expect(yellowColoretteMocks).toHaveBeenCalledWith('⚠️ Your config has 2 warnings.\n');
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should print nothing if no error and no warnings', () => {
|
|
111
|
-
const result = printConfigLintTotals({ ...totalProblemsMock, errors: 0 });
|
|
112
|
-
expect(result).toBeUndefined();
|
|
113
|
-
expect(process.stderr.write).toHaveBeenCalledTimes(0);
|
|
114
|
-
expect(yellowColoretteMocks).toHaveBeenCalledTimes(0);
|
|
115
|
-
expect(redColoretteMocks).toHaveBeenCalledTimes(0);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('getFallbackApisOrExit', () => {
|
|
120
|
-
const redColoretteMocks = red as jest.Mock<any, any>;
|
|
121
|
-
const yellowColoretteMocks = yellow as jest.Mock<any, any>;
|
|
122
|
-
|
|
123
|
-
const apis: Record<string, ResolvedApi> = {
|
|
124
|
-
main: {
|
|
125
|
-
root: 'someFile.yaml',
|
|
126
|
-
styleguide: {},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const config = { apis };
|
|
131
|
-
|
|
132
|
-
beforeEach(() => {
|
|
133
|
-
yellowColoretteMocks.mockImplementation((text: string) => text);
|
|
134
|
-
redColoretteMocks.mockImplementation((text: string) => text);
|
|
135
|
-
jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
136
|
-
jest.spyOn(process, 'exit').mockImplementation();
|
|
137
|
-
});
|
|
138
|
-
afterEach(() => {
|
|
139
|
-
jest.clearAllMocks();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should exit with error because no path provided', async () => {
|
|
143
|
-
const apisConfig = {
|
|
144
|
-
apis: {},
|
|
145
|
-
};
|
|
146
|
-
expect.assertions(1);
|
|
147
|
-
try {
|
|
148
|
-
await getFallbackApisOrExit([''], apisConfig);
|
|
149
|
-
} catch (e) {
|
|
150
|
-
expect(e.message).toEqual('Path cannot be empty.');
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('should error if file from config do not exist', async () => {
|
|
155
|
-
(existsSync as jest.Mock<any, any>).mockImplementationOnce(() => false);
|
|
156
|
-
expect.assertions(3);
|
|
157
|
-
try {
|
|
158
|
-
await getFallbackApisOrExit(undefined, config);
|
|
159
|
-
} catch (e) {
|
|
160
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
161
|
-
'\nsomeFile.yaml does not exist or is invalid.\n\n'
|
|
162
|
-
);
|
|
163
|
-
expect(process.stderr.write).toHaveBeenCalledWith('Please provide a valid path.\n\n');
|
|
164
|
-
expect(e.message).toEqual('Please provide a valid path.');
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should return valid array with results if such file exist', async () => {
|
|
169
|
-
(existsSync as jest.Mock<any, any>).mockImplementationOnce(() => true);
|
|
170
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce((_, path) => path);
|
|
171
|
-
|
|
172
|
-
const result = await getFallbackApisOrExit(undefined, config);
|
|
173
|
-
expect(process.stderr.write).toHaveBeenCalledTimes(0);
|
|
174
|
-
expect(process.exit).toHaveBeenCalledTimes(0);
|
|
175
|
-
expect(result).toStrictEqual([
|
|
176
|
-
{
|
|
177
|
-
alias: 'main',
|
|
178
|
-
path: 'someFile.yaml',
|
|
179
|
-
output: undefined,
|
|
180
|
-
},
|
|
181
|
-
]);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('should exit with error in case if invalid path provided as args', async () => {
|
|
185
|
-
const apisConfig = {
|
|
186
|
-
apis: {},
|
|
187
|
-
};
|
|
188
|
-
(existsSync as jest.Mock<any, any>).mockImplementationOnce(() => false);
|
|
189
|
-
expect.assertions(3);
|
|
190
|
-
|
|
191
|
-
try {
|
|
192
|
-
await getFallbackApisOrExit(['someFile.yaml'], apisConfig);
|
|
193
|
-
} catch (e) {
|
|
194
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
195
|
-
'\nsomeFile.yaml does not exist or is invalid.\n\n'
|
|
196
|
-
);
|
|
197
|
-
expect(process.stderr.write).toHaveBeenCalledWith('Please provide a valid path.\n\n');
|
|
198
|
-
expect(e.message).toEqual('Please provide a valid path.');
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('should exit with error in case if invalid 2 path provided as args', async () => {
|
|
203
|
-
const apisConfig = {
|
|
204
|
-
apis: {},
|
|
205
|
-
};
|
|
206
|
-
(existsSync as jest.Mock<any, any>).mockImplementationOnce(() => false);
|
|
207
|
-
expect.assertions(3);
|
|
208
|
-
try {
|
|
209
|
-
await getFallbackApisOrExit(['someFile.yaml', 'someFile2.yaml'], apisConfig);
|
|
210
|
-
} catch (e) {
|
|
211
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
212
|
-
'\nsomeFile.yaml does not exist or is invalid.\n\n'
|
|
213
|
-
);
|
|
214
|
-
expect(process.stderr.write).toHaveBeenCalledWith('Please provide a valid path.\n\n');
|
|
215
|
-
expect(e.message).toEqual('Please provide a valid path.');
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('should exit with error if only one file exist ', async () => {
|
|
220
|
-
const apisStub = {
|
|
221
|
-
...apis,
|
|
222
|
-
notExist: {
|
|
223
|
-
root: 'notExist.yaml',
|
|
224
|
-
styleguide: {},
|
|
225
|
-
},
|
|
226
|
-
};
|
|
227
|
-
const configStub = { apis: apisStub };
|
|
228
|
-
|
|
229
|
-
const existSyncMock = (existsSync as jest.Mock<any, any>).mockImplementation((path) =>
|
|
230
|
-
path.endsWith('someFile.yaml')
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
expect.assertions(4);
|
|
234
|
-
|
|
235
|
-
try {
|
|
236
|
-
await getFallbackApisOrExit(undefined, configStub);
|
|
237
|
-
} catch (e) {
|
|
238
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
239
|
-
'\nnotExist.yaml does not exist or is invalid.\n\n'
|
|
240
|
-
);
|
|
241
|
-
expect(process.stderr.write).toHaveBeenCalledWith('Please provide a valid path.\n\n');
|
|
242
|
-
expect(process.stderr.write).toHaveBeenCalledTimes(2);
|
|
243
|
-
expect(e.message).toEqual('Please provide a valid path.');
|
|
244
|
-
}
|
|
245
|
-
existSyncMock.mockClear();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('should work ok if it is url passed', async () => {
|
|
249
|
-
(existsSync as jest.Mock<any, any>).mockImplementationOnce(() => false);
|
|
250
|
-
(isAbsoluteUrl as jest.Mock<any, any>).mockImplementation(() => true);
|
|
251
|
-
const apisConfig = {
|
|
252
|
-
apis: {
|
|
253
|
-
main: {
|
|
254
|
-
root: 'https://someLinkt/petstore.yaml?main',
|
|
255
|
-
styleguide: {},
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
const result = await getFallbackApisOrExit(undefined, apisConfig);
|
|
261
|
-
|
|
262
|
-
expect(process.stderr.write).toHaveBeenCalledTimes(0);
|
|
263
|
-
expect(result).toStrictEqual([
|
|
264
|
-
{
|
|
265
|
-
alias: 'main',
|
|
266
|
-
path: 'https://someLinkt/petstore.yaml?main',
|
|
267
|
-
output: undefined,
|
|
268
|
-
},
|
|
269
|
-
]);
|
|
270
|
-
|
|
271
|
-
(isAbsoluteUrl as jest.Mock<any, any>).mockReset();
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('should find alias by filename', async () => {
|
|
275
|
-
(existsSync as jest.Mock<any, any>).mockImplementationOnce(() => true);
|
|
276
|
-
const entry = await getFallbackApisOrExit(['./test.yaml'], {
|
|
277
|
-
apis: {
|
|
278
|
-
main: {
|
|
279
|
-
root: 'test.yaml',
|
|
280
|
-
styleguide: {},
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
});
|
|
284
|
-
expect(entry).toEqual([{ path: './test.yaml', alias: 'main' }]);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should return apis from config with paths and outputs resolved relatively to the config location', async () => {
|
|
288
|
-
(existsSync as jest.Mock<any, any>).mockImplementationOnce(() => true);
|
|
289
|
-
const entry = await getFallbackApisOrExit(undefined, {
|
|
290
|
-
apis: {
|
|
291
|
-
main: {
|
|
292
|
-
root: 'test.yaml',
|
|
293
|
-
output: 'output/test.yaml',
|
|
294
|
-
styleguide: {},
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
configFile: 'project-folder/redocly.yaml',
|
|
298
|
-
});
|
|
299
|
-
expect(entry).toEqual([
|
|
300
|
-
{
|
|
301
|
-
path: expect.stringMatching(/project\-folder\/test\.yaml$/),
|
|
302
|
-
output: expect.stringMatching(/project\-folder\/output\/test\.yaml$/),
|
|
303
|
-
alias: 'main',
|
|
304
|
-
},
|
|
305
|
-
]);
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
describe('langToExt', () => {
|
|
310
|
-
it.each([
|
|
311
|
-
['php', '.php'],
|
|
312
|
-
['c#', '.cs'],
|
|
313
|
-
['shell', '.sh'],
|
|
314
|
-
['curl', '.sh'],
|
|
315
|
-
['bash', '.sh'],
|
|
316
|
-
['javascript', '.js'],
|
|
317
|
-
['js', '.js'],
|
|
318
|
-
['python', '.py'],
|
|
319
|
-
['c', '.c'],
|
|
320
|
-
['c++', '.cpp'],
|
|
321
|
-
['coffeescript', '.litcoffee'],
|
|
322
|
-
['dart', '.dart'],
|
|
323
|
-
['elixir', '.ex'],
|
|
324
|
-
['go', '.go'],
|
|
325
|
-
['groovy', '.groovy'],
|
|
326
|
-
['java', '.java'],
|
|
327
|
-
['kotlin', '.kt'],
|
|
328
|
-
['objective-c', '.m'],
|
|
329
|
-
['perl', '.pl'],
|
|
330
|
-
['powershell', '.ps1'],
|
|
331
|
-
['ruby', '.rb'],
|
|
332
|
-
['rust', '.rs'],
|
|
333
|
-
['scala', '.sc'],
|
|
334
|
-
['swift', '.swift'],
|
|
335
|
-
['typescript', '.ts'],
|
|
336
|
-
['tsx', '.tsx'],
|
|
337
|
-
])('should infer file extension from lang - %s', (lang, expected) => {
|
|
338
|
-
expect(langToExt(lang)).toBe(expected);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('should ignore case when inferring file extension', () => {
|
|
342
|
-
expect(langToExt('JavaScript')).toBe('.js');
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
describe('sorTopLevelKeysForOas', () => {
|
|
347
|
-
it('should sort oas3 top level keys', () => {
|
|
348
|
-
const openApi = {
|
|
349
|
-
openapi: '3.0.0',
|
|
350
|
-
components: {},
|
|
351
|
-
security: [],
|
|
352
|
-
tags: [],
|
|
353
|
-
servers: [],
|
|
354
|
-
paths: {},
|
|
355
|
-
info: {},
|
|
356
|
-
externalDocs: {},
|
|
357
|
-
webhooks: [],
|
|
358
|
-
'x-webhooks': [],
|
|
359
|
-
jsonSchemaDialect: '',
|
|
360
|
-
} as any;
|
|
361
|
-
const orderedKeys = [
|
|
362
|
-
'openapi',
|
|
363
|
-
'info',
|
|
364
|
-
'jsonSchemaDialect',
|
|
365
|
-
'servers',
|
|
366
|
-
'security',
|
|
367
|
-
'tags',
|
|
368
|
-
'externalDocs',
|
|
369
|
-
'paths',
|
|
370
|
-
'webhooks',
|
|
371
|
-
'x-webhooks',
|
|
372
|
-
'components',
|
|
373
|
-
];
|
|
374
|
-
const result = sortTopLevelKeysForOas(openApi);
|
|
375
|
-
|
|
376
|
-
Object.keys(result).forEach((key, index) => {
|
|
377
|
-
expect(key).toEqual(orderedKeys[index]);
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it('should sort oas2 top level keys', () => {
|
|
382
|
-
const openApi = {
|
|
383
|
-
swagger: '2.0.0',
|
|
384
|
-
security: [],
|
|
385
|
-
tags: [],
|
|
386
|
-
paths: {},
|
|
387
|
-
info: {},
|
|
388
|
-
externalDocs: {},
|
|
389
|
-
host: '',
|
|
390
|
-
basePath: '',
|
|
391
|
-
securityDefinitions: [],
|
|
392
|
-
schemes: [],
|
|
393
|
-
consumes: [],
|
|
394
|
-
parameters: [],
|
|
395
|
-
produces: [],
|
|
396
|
-
definitions: [],
|
|
397
|
-
responses: [],
|
|
398
|
-
} as any;
|
|
399
|
-
const orderedKeys = [
|
|
400
|
-
'swagger',
|
|
401
|
-
'info',
|
|
402
|
-
'host',
|
|
403
|
-
'basePath',
|
|
404
|
-
'schemes',
|
|
405
|
-
'consumes',
|
|
406
|
-
'produces',
|
|
407
|
-
'security',
|
|
408
|
-
'tags',
|
|
409
|
-
'externalDocs',
|
|
410
|
-
'paths',
|
|
411
|
-
'definitions',
|
|
412
|
-
'parameters',
|
|
413
|
-
'responses',
|
|
414
|
-
'securityDefinitions',
|
|
415
|
-
];
|
|
416
|
-
const result = sortTopLevelKeysForOas(openApi);
|
|
417
|
-
|
|
418
|
-
Object.keys(result).forEach((key, index) => {
|
|
419
|
-
expect(key).toEqual(orderedKeys[index]);
|
|
420
|
-
});
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
describe('handleErrors', () => {
|
|
425
|
-
const ref = 'openapi/test.yaml';
|
|
426
|
-
|
|
427
|
-
const redColoretteMocks = red as jest.Mock<any, any>;
|
|
428
|
-
const blueColoretteMocks = blue as jest.Mock<any, any>;
|
|
429
|
-
|
|
430
|
-
beforeEach(() => {
|
|
431
|
-
jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
432
|
-
jest.spyOn(process, 'exit').mockImplementation((code) => code as never);
|
|
433
|
-
redColoretteMocks.mockImplementation((text) => text);
|
|
434
|
-
blueColoretteMocks.mockImplementation((text) => text);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
afterEach(() => {
|
|
438
|
-
jest.clearAllMocks();
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it('should handle ResolveError', () => {
|
|
442
|
-
const resolveError = new ResolveError(new Error('File not found.'));
|
|
443
|
-
expect(() => handleError(resolveError, ref)).toThrowError(HandledError);
|
|
444
|
-
expect(redColoretteMocks).toHaveBeenCalledTimes(1);
|
|
445
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
446
|
-
`Failed to resolve API description at openapi/test.yaml:\n\n - File not found.\n\n`
|
|
447
|
-
);
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
it('should handle YamlParseError', () => {
|
|
451
|
-
const yamlParseError = new YamlParseError(new Error('Invalid yaml.'), {} as any);
|
|
452
|
-
expect(() => handleError(yamlParseError, ref)).toThrowError(HandledError);
|
|
453
|
-
expect(redColoretteMocks).toHaveBeenCalledTimes(1);
|
|
454
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
455
|
-
`Failed to parse API description at openapi/test.yaml:\n\n - Invalid yaml.\n\n`
|
|
456
|
-
);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
it('should handle CircularJSONNotSupportedError', () => {
|
|
460
|
-
const circularError = new CircularJSONNotSupportedError(new Error('Circular json'));
|
|
461
|
-
expect(() => handleError(circularError, ref)).toThrowError(HandledError);
|
|
462
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
463
|
-
`Detected circular reference which can't be converted to JSON.\n` +
|
|
464
|
-
`Try to use ${blue('yaml')} output or remove ${blue('--dereferenced')}.\n\n`
|
|
465
|
-
);
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
it('should handle SyntaxError', () => {
|
|
469
|
-
const testError = new SyntaxError('Unexpected identifier');
|
|
470
|
-
testError.stack = 'test stack';
|
|
471
|
-
expect(() => handleError(testError, ref)).toThrowError(HandledError);
|
|
472
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
473
|
-
'Syntax error: Unexpected identifier test stack\n\n'
|
|
474
|
-
);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
it('should throw unknown error', () => {
|
|
478
|
-
const testError = new Error('Test error.');
|
|
479
|
-
expect(() => handleError(testError, ref)).toThrowError(HandledError);
|
|
480
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
481
|
-
`Something went wrong when processing openapi/test.yaml:\n\n - Test error.\n\n`
|
|
482
|
-
);
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
describe('checkIfRulesetExist', () => {
|
|
487
|
-
beforeEach(() => {
|
|
488
|
-
jest.spyOn(process, 'exit').mockImplementation((code?: number) => code as never);
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
afterEach(() => {
|
|
492
|
-
jest.clearAllMocks();
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
it('should throw an error if rules are not provided', () => {
|
|
496
|
-
const rules = {
|
|
497
|
-
oas2: {},
|
|
498
|
-
oas3_0: {},
|
|
499
|
-
oas3_1: {},
|
|
500
|
-
async2: {},
|
|
501
|
-
async3: {},
|
|
502
|
-
arazzo1: {},
|
|
503
|
-
overlay1: {},
|
|
504
|
-
};
|
|
505
|
-
expect(() => checkIfRulesetExist(rules)).toThrowError(
|
|
506
|
-
'⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/'
|
|
507
|
-
);
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
it('should not throw an error if rules are provided', () => {
|
|
511
|
-
const rules = {
|
|
512
|
-
oas2: { 'operation-4xx-response': 'error' },
|
|
513
|
-
oas3_0: {},
|
|
514
|
-
oas3_1: {},
|
|
515
|
-
} as any;
|
|
516
|
-
checkIfRulesetExist(rules);
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
describe('cleanColors', () => {
|
|
521
|
-
it('should remove colors from string', () => {
|
|
522
|
-
const stringWithColors = `String for ${red('test')}`;
|
|
523
|
-
const result = cleanColors(stringWithColors);
|
|
524
|
-
|
|
525
|
-
expect(result).not.toMatch(/\x1b\[\d+m/g);
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
describe('cleanArgs', () => {
|
|
530
|
-
beforeEach(() => {
|
|
531
|
-
// @ts-ignore
|
|
532
|
-
isAbsoluteUrl = jest.requireActual('@redocly/openapi-core').isAbsoluteUrl;
|
|
533
|
-
// @ts-ignore
|
|
534
|
-
existsSync = (value) => jest.requireActual('fs').existsSync(path.resolve(__dirname, value));
|
|
535
|
-
// @ts-ignore
|
|
536
|
-
statSync = (value) => jest.requireActual('fs').statSync(path.resolve(__dirname, value));
|
|
537
|
-
});
|
|
538
|
-
afterEach(() => {
|
|
539
|
-
jest.clearAllMocks();
|
|
540
|
-
});
|
|
541
|
-
it('should remove potentially sensitive data from parsed args', () => {
|
|
542
|
-
const parsedArgs = {
|
|
543
|
-
config: './fixtures/redocly.yaml',
|
|
544
|
-
apis: ['main@v1', 'fixtures/openapi.yaml', 'http://some.url/openapi.yaml'],
|
|
545
|
-
format: 'codeframe',
|
|
546
|
-
input: 'some-input',
|
|
547
|
-
'client-cert': 'some-client-cert',
|
|
548
|
-
'client-key': 'some-client-key',
|
|
549
|
-
'ca-cert': 'some-ca-cert',
|
|
550
|
-
};
|
|
551
|
-
const rawArgs = [
|
|
552
|
-
'redocly',
|
|
553
|
-
'bundle',
|
|
554
|
-
'main@v1',
|
|
555
|
-
'fixtures/openapi.yaml',
|
|
556
|
-
'http://some.url/openapi.yaml',
|
|
557
|
-
'--config=fixtures/redocly.yaml',
|
|
558
|
-
'--format=codeframe',
|
|
559
|
-
'--input=some-input',
|
|
560
|
-
'--client-cert=some-client-cert',
|
|
561
|
-
'--client-key=some-client-key',
|
|
562
|
-
'--ca-cert=some-ca-cert',
|
|
563
|
-
];
|
|
564
|
-
const result = cleanArgs(parsedArgs, rawArgs);
|
|
565
|
-
expect(result.arguments).toEqual(
|
|
566
|
-
JSON.stringify({
|
|
567
|
-
config: 'file-yaml',
|
|
568
|
-
apis: ['api-name@api-version', 'file-yaml', 'http://url'],
|
|
569
|
-
format: 'codeframe',
|
|
570
|
-
input: '***',
|
|
571
|
-
'client-cert': '***',
|
|
572
|
-
'client-key': '***',
|
|
573
|
-
'ca-cert': '***',
|
|
574
|
-
})
|
|
575
|
-
);
|
|
576
|
-
});
|
|
577
|
-
it('should remove potentially sensitive data from a push destination', () => {
|
|
578
|
-
const parsedArgs = {
|
|
579
|
-
destination: '@org/name@version',
|
|
580
|
-
};
|
|
581
|
-
const rawArgs = ['redocly', 'push', '--destination=@org/name@version'];
|
|
582
|
-
const result = cleanArgs(parsedArgs, rawArgs);
|
|
583
|
-
expect(result.arguments).toEqual(
|
|
584
|
-
JSON.stringify({
|
|
585
|
-
destination: '@organization/api-name@api-version',
|
|
586
|
-
})
|
|
587
|
-
);
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
it('should remove potentially sensitive data from raw CLI input', () => {
|
|
591
|
-
const rawInput = [
|
|
592
|
-
'redocly',
|
|
593
|
-
'bundle',
|
|
594
|
-
'api-name@api-version',
|
|
595
|
-
'./fixtures/openapi.yaml',
|
|
596
|
-
'http://some.url/openapi.yaml',
|
|
597
|
-
'--config=fixtures/redocly.yaml',
|
|
598
|
-
'--output',
|
|
599
|
-
'fixtures',
|
|
600
|
-
'--client-cert',
|
|
601
|
-
'fixtures/client-cert.pem',
|
|
602
|
-
'--client-key',
|
|
603
|
-
'fixtures/client-key.pem',
|
|
604
|
-
'--ca-cert',
|
|
605
|
-
'fixtures/ca-cert.pem',
|
|
606
|
-
'--organization',
|
|
607
|
-
'my-org',
|
|
608
|
-
'--input',
|
|
609
|
-
'timeout=10000',
|
|
610
|
-
'--input',
|
|
611
|
-
'{"apiKey":"some=111=1111"}',
|
|
612
|
-
];
|
|
613
|
-
const parsedArgs = {
|
|
614
|
-
apis: ['./fixtures/openapi.yaml', 'http://some.url/openapi.yaml'],
|
|
615
|
-
input: ['timeout=10000', '{"apiKey":"some=111=1111"}'],
|
|
616
|
-
organization: 'my-org',
|
|
617
|
-
'client-cert': 'fixtures/client-cert.pem',
|
|
618
|
-
'client-key': 'fixtures/client-key.pem',
|
|
619
|
-
'ca-cert': 'fixtures/ca-cert.pem',
|
|
620
|
-
config: 'fixtures/redocly.yaml',
|
|
621
|
-
output: 'fixtures',
|
|
622
|
-
};
|
|
623
|
-
const result = cleanArgs(parsedArgs, rawInput);
|
|
624
|
-
expect(result.raw_input).toEqual(
|
|
625
|
-
'redocly bundle api-name@api-version file-yaml http://url --config=file-yaml --output folder --client-cert *** --client-key *** --ca-cert *** --organization *** --input *** --input ***'
|
|
626
|
-
);
|
|
627
|
-
expect(result.arguments).toEqual(
|
|
628
|
-
JSON.stringify({
|
|
629
|
-
apis: ['file-yaml', 'http://url'],
|
|
630
|
-
input: '***',
|
|
631
|
-
organization: '***',
|
|
632
|
-
'client-cert': '***',
|
|
633
|
-
'client-key': '***',
|
|
634
|
-
'ca-cert': '***',
|
|
635
|
-
config: 'file-yaml',
|
|
636
|
-
output: 'folder',
|
|
637
|
-
})
|
|
638
|
-
);
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
it('should preserve safe data from raw CLI input', () => {
|
|
642
|
-
const rawInput = [
|
|
643
|
-
'redocly',
|
|
644
|
-
'lint',
|
|
645
|
-
'./fixtures/openapi.json',
|
|
646
|
-
'--format',
|
|
647
|
-
'stylish',
|
|
648
|
-
'--extends=minimal',
|
|
649
|
-
'--skip-rule',
|
|
650
|
-
'operation-4xx-response',
|
|
651
|
-
];
|
|
652
|
-
const parsedArgs = {
|
|
653
|
-
apis: ['./fixtures/openapi.json'],
|
|
654
|
-
format: 'stylish',
|
|
655
|
-
extends: 'minimal',
|
|
656
|
-
'skip-rule': ['operation-4xx-response'],
|
|
657
|
-
};
|
|
658
|
-
const result = cleanArgs(parsedArgs, rawInput);
|
|
659
|
-
|
|
660
|
-
expect(result.raw_input).toEqual(
|
|
661
|
-
'redocly lint file-json --format stylish --extends=minimal --skip-rule operation-4xx-response'
|
|
662
|
-
);
|
|
663
|
-
|
|
664
|
-
expect(result.arguments).toEqual(
|
|
665
|
-
JSON.stringify({
|
|
666
|
-
apis: ['file-json'],
|
|
667
|
-
format: 'stylish',
|
|
668
|
-
extends: 'minimal',
|
|
669
|
-
'skip-rule': ['operation-4xx-response'],
|
|
670
|
-
})
|
|
671
|
-
);
|
|
672
|
-
});
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
describe('validateFileExtension', () => {
|
|
676
|
-
it('should return current file extension', () => {
|
|
677
|
-
expect(getAndValidateFileExtension('test.json')).toEqual('json');
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
it('should return yaml and print warning if file extension does not supported', () => {
|
|
681
|
-
const stderrMock = jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
682
|
-
(yellow as jest.Mock<any, any>).mockImplementation((text: string) => text);
|
|
683
|
-
|
|
684
|
-
expect(getAndValidateFileExtension('test.xml')).toEqual('yaml');
|
|
685
|
-
expect(stderrMock).toHaveBeenCalledWith(`Unsupported file extension: xml. Using yaml.\n`);
|
|
686
|
-
});
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
describe('writeToFileByExtension', () => {
|
|
690
|
-
beforeEach(() => {
|
|
691
|
-
jest.spyOn(process.stderr, 'write').mockImplementation(jest.fn());
|
|
692
|
-
(yellow as jest.Mock<any, any>).mockImplementation((text: string) => text);
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
afterEach(() => {
|
|
696
|
-
jest.restoreAllMocks();
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
it('should call stringifyYaml function', () => {
|
|
700
|
-
writeToFileByExtension('test data', 'test.yaml');
|
|
701
|
-
expect(stringifyYaml).toHaveBeenCalledWith('test data', { noRefs: false });
|
|
702
|
-
expect(process.stderr.write).toHaveBeenCalledWith(`test data`);
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
it('should call JSON.stringify function', () => {
|
|
706
|
-
const stringifySpy = jest.spyOn(JSON, 'stringify').mockImplementation((data) => data);
|
|
707
|
-
writeToFileByExtension('test data', 'test.json');
|
|
708
|
-
expect(stringifySpy).toHaveBeenCalledWith('test data', null, 2);
|
|
709
|
-
expect(process.stderr.write).toHaveBeenCalledWith(`test data`);
|
|
710
|
-
});
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
describe('runtime platform', () => {
|
|
714
|
-
describe('sanitizePath', () => {
|
|
715
|
-
test.each([
|
|
716
|
-
['C:\\Program Files\\App', 'C:\\Program Files\\App'],
|
|
717
|
-
['/usr/local/bin/app', '/usr/local/bin/app'],
|
|
718
|
-
['invalid|path?name*', 'invalidpathname'],
|
|
719
|
-
['', ''],
|
|
720
|
-
['<>:"|?*', ':'],
|
|
721
|
-
['C:/Program Files\\App', 'C:/Program Files\\App'],
|
|
722
|
-
['path\nname\r', 'pathname'],
|
|
723
|
-
['/usr/local; rm -rf /', '/usr/local rm -rf /'],
|
|
724
|
-
['C:\\data&& dir', 'C:\\data dir'],
|
|
725
|
-
])('should sanitize path %s to %s', (input, expected) => {
|
|
726
|
-
expect(sanitizePath(input)).toBe(expected);
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
describe('sanitizeLocale', () => {
|
|
731
|
-
test.each([
|
|
732
|
-
['en-US', 'en-US'],
|
|
733
|
-
['fr_FR', 'fr_FR'],
|
|
734
|
-
['en<>US', 'enUS'],
|
|
735
|
-
['fr@FR', 'fr@FR'],
|
|
736
|
-
['en_US@#$%', 'en_US@'],
|
|
737
|
-
[' en-US ', 'en-US'],
|
|
738
|
-
['', ''],
|
|
739
|
-
])('should sanitize locale %s to %s', (input, expected) => {
|
|
740
|
-
expect(sanitizeLocale(input)).toBe(expected);
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
|
|
744
|
-
describe('getPlatformSpawnArgs', () => {
|
|
745
|
-
const originalPlatform = process.platform;
|
|
746
|
-
|
|
747
|
-
afterEach(() => {
|
|
748
|
-
Object.defineProperty(process, 'platform', {
|
|
749
|
-
value: originalPlatform,
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
it('should return args for Windows platform', () => {
|
|
754
|
-
Object.defineProperty(process, 'platform', {
|
|
755
|
-
value: 'win32',
|
|
756
|
-
});
|
|
757
|
-
|
|
758
|
-
const result = getPlatformSpawnArgs();
|
|
759
|
-
|
|
760
|
-
expect(result).toEqual({
|
|
761
|
-
npxExecutableName: 'npx.cmd',
|
|
762
|
-
sanitize: expect.any(Function),
|
|
763
|
-
shell: true,
|
|
764
|
-
});
|
|
765
|
-
});
|
|
766
|
-
|
|
767
|
-
it('should return args for non-Windows platform', () => {
|
|
768
|
-
Object.defineProperty(process, 'platform', {
|
|
769
|
-
value: 'linux',
|
|
770
|
-
});
|
|
771
|
-
|
|
772
|
-
const result = getPlatformSpawnArgs();
|
|
773
|
-
|
|
774
|
-
expect(result).toEqual({
|
|
775
|
-
npxExecutableName: 'npx',
|
|
776
|
-
sanitize: expect.any(Function),
|
|
777
|
-
shell: false,
|
|
778
|
-
});
|
|
779
|
-
});
|
|
780
|
-
});
|
|
781
|
-
});
|