@redocly/cli 1.18.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
- package/lib/__mocks__/@redocly/openapi-core.js +1 -0
- package/lib/__mocks__/fs.d.ts +0 -1
- package/lib/__mocks__/perf_hooks.d.ts +0 -1
- package/lib/__mocks__/redoc.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +21 -23
- package/lib/__tests__/commands/bundle.test.js +21 -30
- package/lib/__tests__/commands/join.test.js +101 -70
- package/lib/__tests__/commands/lint.test.js +54 -54
- package/lib/__tests__/commands/push-region.test.js +24 -25
- package/lib/__tests__/commands/push.test.js +269 -170
- package/lib/__tests__/fetch-with-timeout.test.js +3 -12
- package/lib/__tests__/fixtures/config.d.ts +0 -1
- package/lib/__tests__/utils.test.js +32 -37
- package/lib/__tests__/wrapper.test.js +31 -20
- package/lib/cms/api/__tests__/api.client.test.js +29 -38
- package/lib/cms/api/api-client.d.ts +0 -2
- package/lib/cms/api/api-client.js +106 -127
- package/lib/cms/api/api-keys.js +1 -2
- package/lib/cms/api/domains.js +1 -2
- package/lib/cms/commands/__tests__/push-status.test.js +251 -162
- package/lib/cms/commands/__tests__/push.test.js +120 -102
- package/lib/cms/commands/__tests__/utils.test.js +12 -21
- package/lib/cms/commands/push-status.d.ts +3 -2
- package/lib/cms/commands/push-status.js +94 -106
- package/lib/cms/commands/push.d.ts +3 -2
- package/lib/cms/commands/push.js +66 -74
- package/lib/cms/commands/utils.js +20 -34
- package/lib/commands/build-docs/index.d.ts +2 -2
- package/lib/commands/build-docs/index.js +8 -17
- package/lib/commands/build-docs/utils.js +26 -38
- package/lib/commands/bundle.d.ts +2 -2
- package/lib/commands/bundle.js +70 -94
- package/lib/commands/join.d.ts +2 -2
- package/lib/commands/join.js +375 -388
- package/lib/commands/lint.d.ts +2 -2
- package/lib/commands/lint.js +64 -75
- package/lib/commands/login.d.ts +3 -2
- package/lib/commands/login.js +9 -21
- package/lib/commands/preview-docs/index.d.ts +2 -2
- package/lib/commands/preview-docs/index.js +92 -106
- package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
- package/lib/commands/preview-docs/preview-server/server.js +6 -6
- package/lib/commands/preview-project/index.d.ts +2 -1
- package/lib/commands/preview-project/index.js +5 -14
- package/lib/commands/push.d.ts +8 -11
- package/lib/commands/push.js +177 -195
- package/lib/commands/split/__tests__/index.test.js +31 -25
- package/lib/commands/split/index.d.ts +2 -1
- package/lib/commands/split/index.js +20 -33
- package/lib/commands/stats.d.ts +2 -2
- package/lib/commands/stats.js +34 -45
- package/lib/index.js +32 -46
- package/lib/types.d.ts +2 -2
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
- package/lib/utils/fetch-with-timeout.js +7 -12
- package/lib/utils/getCommandNameFromArgs.js +2 -4
- package/lib/utils/js-utils.js +6 -7
- package/lib/utils/miscellaneous.d.ts +4 -1
- package/lib/utils/miscellaneous.js +130 -152
- package/lib/utils/update-version-notifier.js +4 -13
- package/lib/wrapper.d.ts +9 -2
- package/lib/wrapper.js +27 -16
- package/package.json +3 -3
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__tests__/commands/build-docs.test.ts +5 -4
- package/src/__tests__/commands/join.test.ts +51 -51
- package/src/__tests__/commands/push-region.test.ts +10 -8
- package/src/__tests__/commands/push.test.ts +127 -102
- package/src/__tests__/utils.test.ts +1 -0
- package/src/__tests__/wrapper.test.ts +24 -2
- package/src/cms/commands/__tests__/push-status.test.ts +70 -56
- package/src/cms/commands/__tests__/push.test.ts +30 -24
- package/src/cms/commands/push-status.ts +8 -7
- package/src/cms/commands/push.ts +12 -9
- package/src/commands/build-docs/index.ts +10 -5
- package/src/commands/bundle.ts +14 -6
- package/src/commands/join.ts +6 -2
- package/src/commands/lint.ts +9 -3
- package/src/commands/login.ts +4 -2
- package/src/commands/preview-docs/index.ts +6 -1
- package/src/commands/preview-project/index.ts +5 -4
- package/src/commands/push.ts +13 -15
- package/src/commands/split/__tests__/index.test.ts +17 -6
- package/src/commands/split/index.ts +4 -2
- package/src/commands/stats.ts +4 -2
- package/src/utils/miscellaneous.ts +11 -1
- package/src/wrapper.ts +37 -11
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,48 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const index_1 = require("../index");
|
|
13
4
|
const path = require("path");
|
|
14
5
|
const openapiCore = require("@redocly/openapi-core");
|
|
15
6
|
const colorette_1 = require("colorette");
|
|
7
|
+
const miscellaneous_1 = require("../../../utils/__mocks__/miscellaneous");
|
|
16
8
|
const utils = require('../../../utils/miscellaneous');
|
|
17
|
-
jest.mock('../../../utils/miscellaneous', () => (
|
|
18
|
-
jest.
|
|
9
|
+
jest.mock('../../../utils/miscellaneous', () => ({
|
|
10
|
+
...jest.requireActual('../../../utils/miscellaneous'),
|
|
11
|
+
writeToFileByExtension: jest.fn(),
|
|
12
|
+
}));
|
|
13
|
+
jest.mock('@redocly/openapi-core', () => ({
|
|
14
|
+
...jest.requireActual('@redocly/openapi-core'),
|
|
15
|
+
isRef: jest.fn(),
|
|
16
|
+
}));
|
|
19
17
|
describe('#split', () => {
|
|
20
18
|
const openapiDir = 'test';
|
|
21
19
|
const componentsFiles = {};
|
|
22
|
-
it('should split the file and show the success message', () =>
|
|
20
|
+
it('should split the file and show the success message', async () => {
|
|
23
21
|
const filePath = 'packages/cli/src/commands/split/__tests__/fixtures/spec.json';
|
|
24
22
|
jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
await (0, index_1.handleSplit)({
|
|
24
|
+
argv: {
|
|
25
|
+
api: filePath,
|
|
26
|
+
outDir: openapiDir,
|
|
27
|
+
separator: '_',
|
|
28
|
+
},
|
|
29
|
+
config: (0, miscellaneous_1.loadConfigAndHandleErrors)(),
|
|
30
|
+
version: 'cli-version',
|
|
29
31
|
});
|
|
30
32
|
expect(process.stderr.write).toBeCalledTimes(2);
|
|
31
33
|
expect(process.stderr.write.mock.calls[0][0]).toBe(`🪓 Document: ${(0, colorette_1.blue)(filePath)} ${(0, colorette_1.green)('is successfully split')}
|
|
32
34
|
and all related files are saved to the directory: ${(0, colorette_1.blue)(openapiDir)} \n`);
|
|
33
35
|
expect(process.stderr.write.mock.calls[1][0]).toContain(`${filePath}: split processed in <test>ms`);
|
|
34
|
-
})
|
|
35
|
-
it('should use the correct separator', () =>
|
|
36
|
+
});
|
|
37
|
+
it('should use the correct separator', async () => {
|
|
36
38
|
const filePath = 'packages/cli/src/commands/split/__tests__/fixtures/spec.json';
|
|
37
39
|
jest.spyOn(utils, 'pathToFilename').mockImplementation(() => 'newFilePath');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
await (0, index_1.handleSplit)({
|
|
41
|
+
argv: {
|
|
42
|
+
api: filePath,
|
|
43
|
+
outDir: openapiDir,
|
|
44
|
+
separator: '_',
|
|
45
|
+
},
|
|
46
|
+
config: (0, miscellaneous_1.loadConfigAndHandleErrors)(),
|
|
47
|
+
version: 'cli-version',
|
|
42
48
|
});
|
|
43
49
|
expect(utils.pathToFilename).toBeCalledWith(expect.anything(), '_');
|
|
44
50
|
utils.pathToFilename.mockRestore();
|
|
45
|
-
})
|
|
51
|
+
});
|
|
46
52
|
it('should have correct path with paths', () => {
|
|
47
53
|
const openapi = require('./fixtures/spec.json');
|
|
48
54
|
jest.spyOn(openapiCore, 'slash').mockImplementation(() => 'paths/test.yaml');
|
|
@@ -67,7 +73,7 @@ describe('#split', () => {
|
|
|
67
73
|
expect(openapiCore.slash).toHaveBeenCalledWith('webhooks/test.yaml');
|
|
68
74
|
expect(path.relative).toHaveBeenCalledWith('test', 'test/webhooks/test.yaml');
|
|
69
75
|
});
|
|
70
|
-
it('should create correct folder name for code samples', () =>
|
|
76
|
+
it('should create correct folder name for code samples', async () => {
|
|
71
77
|
const openapi = require('./fixtures/samples.json');
|
|
72
78
|
const fs = require('fs');
|
|
73
79
|
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { });
|
|
@@ -81,5 +87,5 @@ describe('#split', () => {
|
|
|
81
87
|
expect(utils.escapeLanguageName).nthReturnedWith(3, 'VisualBasic');
|
|
82
88
|
expect(utils.escapeLanguageName).toBeCalledTimes(3);
|
|
83
89
|
utils.escapeLanguageName.mockRestore();
|
|
84
|
-
})
|
|
90
|
+
});
|
|
85
91
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Oas3PathItem, Referenced } from './types';
|
|
2
|
+
import type { CommandArgs } from '../../wrapper';
|
|
2
3
|
export type SplitOptions = {
|
|
3
4
|
api: string;
|
|
4
5
|
outDir: string;
|
|
5
6
|
separator: string;
|
|
6
7
|
config?: string;
|
|
7
8
|
};
|
|
8
|
-
export declare function handleSplit(argv: SplitOptions): Promise<void>;
|
|
9
|
+
export declare function handleSplit({ argv, collectSpecData }: CommandArgs<SplitOptions>): Promise<void>;
|
|
9
10
|
export declare function startsWithComponents(node: string): boolean;
|
|
10
11
|
export declare function crawl(object: unknown, visitor: (node: Record<string, unknown>) => void): void;
|
|
11
12
|
declare function iteratePathItems(pathItems: Record<string, Referenced<Oas3PathItem>> | undefined, openapiDir: string, outDir: string, componentsFiles: object, pathSeparator: string, codeSamplesPathPrefix: string | undefined, ext: string): void;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
3
|
+
exports.handleSplit = handleSplit;
|
|
4
|
+
exports.startsWithComponents = startsWithComponents;
|
|
5
|
+
exports.crawl = crawl;
|
|
6
|
+
exports.iteratePathItems = iteratePathItems;
|
|
13
7
|
const colorette_1 = require("colorette");
|
|
14
8
|
const fs = require("fs");
|
|
15
9
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
@@ -19,20 +13,18 @@ const perf_hooks_1 = require("perf_hooks");
|
|
|
19
13
|
const miscellaneous_1 = require("../../utils/miscellaneous");
|
|
20
14
|
const js_utils_1 = require("../../utils/js-utils");
|
|
21
15
|
const types_1 = require("./types");
|
|
22
|
-
function handleSplit(argv) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
async function handleSplit({ argv, collectSpecData }) {
|
|
17
|
+
const startedAt = perf_hooks_1.performance.now();
|
|
18
|
+
const { api, outDir, separator } = argv;
|
|
19
|
+
validateDefinitionFileName(api);
|
|
20
|
+
const ext = (0, miscellaneous_1.getAndValidateFileExtension)(api);
|
|
21
|
+
const openapi = (0, miscellaneous_1.readYaml)(api);
|
|
22
|
+
collectSpecData?.(openapi);
|
|
23
|
+
splitDefinition(openapi, outDir, separator, ext);
|
|
24
|
+
process.stderr.write(`🪓 Document: ${(0, colorette_1.blue)(api)} ${(0, colorette_1.green)('is successfully split')}
|
|
31
25
|
and all related files are saved to the directory: ${(0, colorette_1.blue)(outDir)} \n`);
|
|
32
|
-
|
|
33
|
-
});
|
|
26
|
+
(0, miscellaneous_1.printExecutionTime)('split', startedAt, api);
|
|
34
27
|
}
|
|
35
|
-
exports.handleSplit = handleSplit;
|
|
36
28
|
function splitDefinition(openapi, openapiDir, pathSeparator, ext) {
|
|
37
29
|
fs.mkdirSync(openapiDir, { recursive: true });
|
|
38
30
|
const componentsFiles = {};
|
|
@@ -47,7 +39,6 @@ function splitDefinition(openapi, openapiDir, pathSeparator, ext) {
|
|
|
47
39
|
function startsWithComponents(node) {
|
|
48
40
|
return node.startsWith(`#/${types_1.COMPONENTS}/`);
|
|
49
41
|
}
|
|
50
|
-
exports.startsWithComponents = startsWithComponents;
|
|
51
42
|
function isSupportedExtension(filename) {
|
|
52
43
|
return filename.endsWith('.yaml') || filename.endsWith('.yml') || filename.endsWith('.json');
|
|
53
44
|
}
|
|
@@ -98,7 +89,6 @@ function crawl(object, visitor) {
|
|
|
98
89
|
crawl(object[key], visitor);
|
|
99
90
|
}
|
|
100
91
|
}
|
|
101
|
-
exports.crawl = crawl;
|
|
102
92
|
function replace$Refs(obj, relativeFrom, componentFiles = {}) {
|
|
103
93
|
crawl(obj, (node) => {
|
|
104
94
|
if (node.$ref && typeof node.$ref === 'string' && startsWithComponents(node.$ref)) {
|
|
@@ -183,10 +173,9 @@ function getFileNamePath(componentDirPath, componentName, ext) {
|
|
|
183
173
|
return path.join(componentDirPath, componentName) + `.${ext}`;
|
|
184
174
|
}
|
|
185
175
|
function gatherComponentsFiles(components, componentsFiles, componentType, componentName, filename) {
|
|
186
|
-
var _a, _b;
|
|
187
176
|
let inherits = [];
|
|
188
177
|
if (componentType === types_1.OPENAPI3_COMPONENT.Schemas) {
|
|
189
|
-
inherits = (
|
|
178
|
+
inherits = (components?.[componentType]?.[componentName]?.allOf || [])
|
|
190
179
|
.map(({ $ref }) => $ref)
|
|
191
180
|
.filter(openapi_core_1.isTruthy);
|
|
192
181
|
}
|
|
@@ -204,7 +193,7 @@ function iteratePathItems(pathItems, openapiDir, outDir, componentsFiles, pathSe
|
|
|
204
193
|
continue;
|
|
205
194
|
for (const method of types_1.OPENAPI3_METHOD_NAMES) {
|
|
206
195
|
const methodData = pathData[method];
|
|
207
|
-
const methodDataXCode =
|
|
196
|
+
const methodDataXCode = methodData?.['x-code-samples'] || methodData?.['x-codeSamples'];
|
|
208
197
|
if (!methodDataXCode || !Array.isArray(methodDataXCode)) {
|
|
209
198
|
continue;
|
|
210
199
|
}
|
|
@@ -228,7 +217,6 @@ function iteratePathItems(pathItems, openapiDir, outDir, componentsFiles, pathSe
|
|
|
228
217
|
traverseDirectoryDeep(outDir, traverseDirectoryDeepCallback, componentsFiles);
|
|
229
218
|
}
|
|
230
219
|
}
|
|
231
|
-
exports.iteratePathItems = iteratePathItems;
|
|
232
220
|
function iterateComponents(openapi, openapiDir, componentsFiles, ext) {
|
|
233
221
|
const { components } = openapi;
|
|
234
222
|
if (components) {
|
|
@@ -240,19 +228,18 @@ function iterateComponents(openapi, openapiDir, componentsFiles, ext) {
|
|
|
240
228
|
// eslint-disable-next-line no-inner-declarations
|
|
241
229
|
function iterateAndGatherComponentsFiles(componentType) {
|
|
242
230
|
const componentDirPath = path.join(componentsDir, componentType);
|
|
243
|
-
for (const componentName of Object.keys(
|
|
231
|
+
for (const componentName of Object.keys(components?.[componentType] || {})) {
|
|
244
232
|
const filename = getFileNamePath(componentDirPath, componentName, ext);
|
|
245
233
|
gatherComponentsFiles(components, componentsFiles, componentType, componentName, filename);
|
|
246
234
|
}
|
|
247
235
|
}
|
|
248
236
|
// eslint-disable-next-line no-inner-declarations
|
|
249
237
|
function iterateComponentTypes(componentType) {
|
|
250
|
-
var _a, _b, _c;
|
|
251
238
|
const componentDirPath = path.join(componentsDir, componentType);
|
|
252
239
|
createComponentDir(componentDirPath, componentType);
|
|
253
|
-
for (const componentName of Object.keys(
|
|
240
|
+
for (const componentName of Object.keys(components?.[componentType] || {})) {
|
|
254
241
|
const filename = getFileNamePath(componentDirPath, componentName, ext);
|
|
255
|
-
const componentData =
|
|
242
|
+
const componentData = components?.[componentType]?.[componentName];
|
|
256
243
|
replace$Refs(componentData, path.dirname(filename), componentsFiles);
|
|
257
244
|
implicitlyReferenceDiscriminator(componentData, extractFileNameFromPath(filename), filename, componentsFiles.schemas || {});
|
|
258
245
|
if (doesFileDiffer(filename, componentData)) {
|
|
@@ -263,7 +250,7 @@ function iterateComponents(openapi, openapiDir, componentsFiles, ext) {
|
|
|
263
250
|
}
|
|
264
251
|
if (isNotSecurityComponentType(componentType)) {
|
|
265
252
|
// security schemas must referenced from components
|
|
266
|
-
|
|
253
|
+
delete openapi.components?.[componentType]?.[componentName];
|
|
267
254
|
}
|
|
268
255
|
}
|
|
269
256
|
removeEmptyComponents(openapi, componentType);
|
package/lib/commands/stats.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Config } from '@redocly/openapi-core';
|
|
2
1
|
import type { OutputFormat } from '@redocly/openapi-core';
|
|
2
|
+
import type { CommandArgs } from '../wrapper';
|
|
3
3
|
export type StatsOptions = {
|
|
4
4
|
api?: string;
|
|
5
5
|
format: OutputFormat;
|
|
6
6
|
config?: string;
|
|
7
7
|
};
|
|
8
|
-
export declare function handleStats(argv
|
|
8
|
+
export declare function handleStats({ argv, config, collectSpecData }: CommandArgs<StatsOptions>): Promise<void>;
|
package/lib/commands/stats.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.handleStats =
|
|
3
|
+
exports.handleStats = handleStats;
|
|
13
4
|
const perf_hooks_1 = require("perf_hooks");
|
|
14
5
|
const colors = require("colorette");
|
|
15
6
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
@@ -68,40 +59,38 @@ function printStats(statsAccumulator, api, startedAt, format) {
|
|
|
68
59
|
break;
|
|
69
60
|
}
|
|
70
61
|
}
|
|
71
|
-
function handleStats(argv, config) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
printStats(statsAccumulator, path, startedAt, argv.format);
|
|
62
|
+
async function handleStats({ argv, config, collectSpecData }) {
|
|
63
|
+
const [{ path }] = await (0, miscellaneous_1.getFallbackApisOrExit)(argv.api ? [argv.api] : [], config);
|
|
64
|
+
const externalRefResolver = new openapi_core_1.BaseResolver(config.resolve);
|
|
65
|
+
const { bundle: document } = await (0, openapi_core_1.bundle)({ config, ref: path });
|
|
66
|
+
collectSpecData?.(document.parsed);
|
|
67
|
+
const lintConfig = config.styleguide;
|
|
68
|
+
const specVersion = (0, openapi_core_1.detectSpec)(document.parsed);
|
|
69
|
+
const types = (0, openapi_core_1.normalizeTypes)(lintConfig.extendTypes((0, openapi_core_1.getTypes)(specVersion), specVersion), lintConfig);
|
|
70
|
+
const startedAt = perf_hooks_1.performance.now();
|
|
71
|
+
const ctx = {
|
|
72
|
+
problems: [],
|
|
73
|
+
oasVersion: specVersion,
|
|
74
|
+
visitorsData: {},
|
|
75
|
+
};
|
|
76
|
+
const resolvedRefMap = await (0, openapi_core_1.resolveDocument)({
|
|
77
|
+
rootDocument: document,
|
|
78
|
+
rootType: types.Root,
|
|
79
|
+
externalRefResolver,
|
|
80
|
+
});
|
|
81
|
+
const statsVisitor = (0, openapi_core_1.normalizeVisitors)([
|
|
82
|
+
{
|
|
83
|
+
severity: 'warn',
|
|
84
|
+
ruleId: 'stats',
|
|
85
|
+
visitor: (0, openapi_core_1.Stats)(statsAccumulator),
|
|
86
|
+
},
|
|
87
|
+
], types);
|
|
88
|
+
(0, openapi_core_1.walkDocument)({
|
|
89
|
+
document,
|
|
90
|
+
rootType: types.Root,
|
|
91
|
+
normalizedVisitors: statsVisitor,
|
|
92
|
+
resolvedRefMap,
|
|
93
|
+
ctx,
|
|
105
94
|
});
|
|
95
|
+
printStats(statsAccumulator, path, startedAt, argv.format);
|
|
106
96
|
}
|
|
107
|
-
exports.handleStats = handleStats;
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
4
|
require("./utils/assert-node-version");
|
|
14
5
|
const yargs = require("yargs");
|
|
@@ -502,51 +493,47 @@ yargs
|
|
|
502
493
|
process.env.REDOCLY_CLI_COMMAND = 'bundle';
|
|
503
494
|
(0, wrapper_1.commandWrapper)(bundle_1.handleBundle)(argv);
|
|
504
495
|
})
|
|
505
|
-
.command('check-config', 'Lint the Redocly configuration file.', (yargs) =>
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
'
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
},
|
|
516
|
-
});
|
|
496
|
+
.command('check-config', 'Lint the Redocly configuration file.', async (yargs) => yargs.option({
|
|
497
|
+
config: {
|
|
498
|
+
description: 'Path to the config file.',
|
|
499
|
+
type: 'string',
|
|
500
|
+
},
|
|
501
|
+
'lint-config': {
|
|
502
|
+
description: 'Severity level for config file linting.',
|
|
503
|
+
choices: ['warn', 'error'],
|
|
504
|
+
default: 'error',
|
|
505
|
+
},
|
|
517
506
|
}), (argv) => {
|
|
518
507
|
process.env.REDOCLY_CLI_COMMAND = 'check-config';
|
|
519
508
|
(0, wrapper_1.commandWrapper)()(argv);
|
|
520
509
|
})
|
|
521
|
-
.command('login', 'Login to the Redocly API registry with an access token.', (yargs) =>
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
},
|
|
537
|
-
});
|
|
510
|
+
.command('login', 'Login to the Redocly API registry with an access token.', async (yargs) => yargs.options({
|
|
511
|
+
verbose: {
|
|
512
|
+
description: 'Include additional output.',
|
|
513
|
+
type: 'boolean',
|
|
514
|
+
},
|
|
515
|
+
region: {
|
|
516
|
+
description: 'Specify a region.',
|
|
517
|
+
alias: 'r',
|
|
518
|
+
choices: types_1.regionChoices,
|
|
519
|
+
},
|
|
520
|
+
config: {
|
|
521
|
+
description: 'Path to the config file.',
|
|
522
|
+
requiresArg: true,
|
|
523
|
+
type: 'string',
|
|
524
|
+
},
|
|
538
525
|
}), (argv) => {
|
|
539
526
|
process.env.REDOCLY_CLI_COMMAND = 'login';
|
|
540
527
|
(0, wrapper_1.commandWrapper)(login_1.handleLogin)(argv);
|
|
541
528
|
})
|
|
542
|
-
.command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, (argv) =>
|
|
529
|
+
.command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, async (argv) => {
|
|
543
530
|
process.env.REDOCLY_CLI_COMMAND = 'logout';
|
|
544
|
-
|
|
531
|
+
await (0, wrapper_1.commandWrapper)(async () => {
|
|
545
532
|
const client = new openapi_core_1.RedoclyClient();
|
|
546
533
|
client.logout();
|
|
547
534
|
process.stdout.write('Logged out from the Redocly account. ✋\n');
|
|
548
|
-
})
|
|
549
|
-
})
|
|
535
|
+
})(argv);
|
|
536
|
+
})
|
|
550
537
|
.command('preview', 'Preview Redocly project using one of the product NPM packages.', (yargs) => yargs.options({
|
|
551
538
|
product: {
|
|
552
539
|
type: 'string',
|
|
@@ -657,14 +644,13 @@ yargs
|
|
|
657
644
|
},
|
|
658
645
|
})
|
|
659
646
|
.check((argv) => {
|
|
660
|
-
|
|
661
|
-
if (argv.theme && !((_a = argv.theme) === null || _a === void 0 ? void 0 : _a.openapi))
|
|
647
|
+
if (argv.theme && !argv.theme?.openapi)
|
|
662
648
|
throw Error('Invalid option: theme.openapi not set');
|
|
663
649
|
return true;
|
|
664
|
-
}), (argv) =>
|
|
650
|
+
}), async (argv) => {
|
|
665
651
|
process.env.REDOCLY_CLI_COMMAND = 'build-docs';
|
|
666
652
|
(0, wrapper_1.commandWrapper)(build_docs_1.handlerBuildCommand)(argv);
|
|
667
|
-
})
|
|
653
|
+
})
|
|
668
654
|
.completion('completion', 'Generate autocomplete script for `redocly` command.')
|
|
669
655
|
.demandCommand(1)
|
|
670
656
|
.middleware([update_version_notifier_1.notifyUpdateCliVersion])
|
package/lib/types.d.ts
CHANGED
|
@@ -22,9 +22,9 @@ export type Entrypoint = {
|
|
|
22
22
|
path: string;
|
|
23
23
|
alias?: string;
|
|
24
24
|
};
|
|
25
|
-
export declare const outputExtensions:
|
|
25
|
+
export declare const outputExtensions: ReadonlyArray<BundleOutputFormat>;
|
|
26
26
|
export type OutputExtensions = 'json' | 'yaml' | 'yml' | undefined;
|
|
27
|
-
export declare const regionChoices:
|
|
27
|
+
export declare const regionChoices: ReadonlyArray<Region>;
|
|
28
28
|
export type CommandOptions = StatsOptions | SplitOptions | JoinOptions | PushOptions | PushBhOptions | LintOptions | BundleOptions | LoginOptions | PreviewDocsOptions | BuildDocsArgv | PushStatusOptions | VerifyConfigOptions | PreviewProjectOptions;
|
|
29
29
|
export type VerifyConfigOptions = {
|
|
30
30
|
config?: string;
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const node_fetch_1 = require("node-fetch");
|
|
13
4
|
const abort_controller_1 = require("abort-controller");
|
|
14
5
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
15
6
|
const TIMEOUT = 3000;
|
|
16
|
-
exports.default = (url, options = {}) =>
|
|
7
|
+
exports.default = async (url, options = {}) => {
|
|
17
8
|
try {
|
|
18
9
|
const controller = new abort_controller_1.default();
|
|
19
10
|
const timeout = setTimeout(() => {
|
|
20
11
|
controller.abort();
|
|
21
12
|
}, TIMEOUT);
|
|
22
|
-
const res =
|
|
13
|
+
const res = await (0, node_fetch_1.default)(url, {
|
|
14
|
+
signal: controller.signal,
|
|
15
|
+
...options,
|
|
16
|
+
agent: (0, openapi_core_1.getProxyAgent)(),
|
|
17
|
+
});
|
|
23
18
|
clearTimeout(timeout);
|
|
24
19
|
return res;
|
|
25
20
|
}
|
|
26
21
|
catch (e) {
|
|
27
22
|
return;
|
|
28
23
|
}
|
|
29
|
-
}
|
|
24
|
+
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCommandNameFromArgs =
|
|
3
|
+
exports.getCommandNameFromArgs = getCommandNameFromArgs;
|
|
4
4
|
function getCommandNameFromArgs(argv) {
|
|
5
|
-
|
|
6
|
-
return (_b = (_a = argv === null || argv === void 0 ? void 0 : argv._) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
|
|
5
|
+
return argv?._?.[0] ?? '';
|
|
7
6
|
}
|
|
8
|
-
exports.getCommandNameFromArgs = getCommandNameFromArgs;
|
package/lib/utils/js-utils.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isObject = isObject;
|
|
4
|
+
exports.isEmptyObject = isEmptyObject;
|
|
5
|
+
exports.isString = isString;
|
|
6
|
+
exports.keysOf = keysOf;
|
|
7
|
+
exports.capitalize = capitalize;
|
|
4
8
|
function isObject(obj) {
|
|
5
9
|
const type = typeof obj;
|
|
6
10
|
return type === 'function' || (type === 'object' && !!obj);
|
|
7
11
|
}
|
|
8
|
-
exports.isObject = isObject;
|
|
9
12
|
function isEmptyObject(obj) {
|
|
10
13
|
return !!obj && Object.keys(obj).length === 0;
|
|
11
14
|
}
|
|
12
|
-
exports.isEmptyObject = isEmptyObject;
|
|
13
15
|
function isString(str) {
|
|
14
16
|
return Object.prototype.toString.call(str) === '[object String]';
|
|
15
17
|
}
|
|
16
|
-
exports.isString = isString;
|
|
17
18
|
function keysOf(obj) {
|
|
18
19
|
if (!obj)
|
|
19
20
|
return [];
|
|
20
21
|
return Object.keys(obj);
|
|
21
22
|
}
|
|
22
|
-
exports.keysOf = keysOf;
|
|
23
23
|
function capitalize(s) {
|
|
24
|
-
if (
|
|
24
|
+
if (s?.length > 0) {
|
|
25
25
|
return s[0].toUpperCase() + s.slice(1);
|
|
26
26
|
}
|
|
27
27
|
return s;
|
|
28
28
|
}
|
|
29
|
-
exports.capitalize = capitalize;
|
|
@@ -46,7 +46,7 @@ export declare function loadConfigAndHandleErrors(options?: {
|
|
|
46
46
|
export declare function sortTopLevelKeysForOas(document: Oas3Definition | Oas2Definition): Oas3Definition | Oas2Definition;
|
|
47
47
|
export declare function checkIfRulesetExist(rules: typeof StyleguideConfig.prototype.rules): void;
|
|
48
48
|
export declare function cleanColors(input: string): string;
|
|
49
|
-
export declare function sendTelemetry(argv: Arguments | undefined, exit_code: ExitCode, has_config: boolean | undefined): Promise<void>;
|
|
49
|
+
export declare function sendTelemetry(argv: Arguments | undefined, exit_code: ExitCode, has_config: boolean | undefined, spec_version: string | undefined, spec_keyword: string | undefined, spec_full_version: string | undefined): Promise<void>;
|
|
50
50
|
export type ExitCode = 0 | 1 | 2;
|
|
51
51
|
export type Analytics = {
|
|
52
52
|
event: string;
|
|
@@ -62,6 +62,9 @@ export type Analytics = {
|
|
|
62
62
|
environment_ci?: string;
|
|
63
63
|
raw_input: string;
|
|
64
64
|
has_config?: boolean;
|
|
65
|
+
spec_version?: string;
|
|
66
|
+
spec_keyword?: string;
|
|
67
|
+
spec_full_version?: string;
|
|
65
68
|
};
|
|
66
69
|
export declare function cleanArgs(args: CommandOptions): Record<string, unknown>;
|
|
67
70
|
export declare function cleanRawInput(argv: string[]): string;
|