@redocly/cli 1.9.0 → 1.10.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 +20 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +1 -0
- package/lib/__mocks__/@redocly/openapi-core.js +4 -2
- package/lib/__mocks__/documents.d.ts +58 -0
- package/lib/__mocks__/documents.js +63 -3
- package/lib/__tests__/commands/join.test.js +126 -3
- package/lib/cms/api/__tests__/api.client.test.js +3 -0
- package/lib/cms/api/api-client.js +15 -4
- package/lib/commands/join.d.ts +2 -1
- package/lib/commands/join.js +21 -27
- package/lib/commands/push.js +8 -2
- package/lib/commands/split/index.d.ts +3 -1
- package/lib/commands/split/index.js +10 -9
- package/lib/commands/split/types.d.ts +1 -2
- package/lib/commands/split/types.js +1 -2
- package/lib/utils/fetch-with-timeout.js +2 -1
- package/lib/utils/js-utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/__mocks__/@redocly/openapi-core.ts +5 -1
- package/src/__mocks__/documents.ts +63 -2
- package/src/__tests__/commands/join.test.ts +137 -3
- package/src/cms/api/__tests__/api.client.test.ts +3 -0
- package/src/cms/api/api-client.ts +18 -5
- package/src/commands/join.ts +26 -32
- package/src/commands/push.ts +9 -2
- package/src/commands/split/index.ts +24 -25
- package/src/commands/split/types.ts +1 -3
- package/src/utils/fetch-with-timeout.ts +6 -1
- package/src/utils/js-utils.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { red, blue, yellow, green } from 'colorette';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import { parseYaml, slash, isRef, isTruthy } from '@redocly/openapi-core';
|
|
4
|
-
import type { OasRef } from '@redocly/openapi-core';
|
|
5
4
|
import * as path from 'path';
|
|
6
5
|
import { performance } from 'perf_hooks';
|
|
7
6
|
const isEqual = require('lodash.isequal');
|
|
8
|
-
|
|
9
7
|
import {
|
|
10
8
|
printExecutionTime,
|
|
11
9
|
pathToFilename,
|
|
@@ -16,8 +14,16 @@ import {
|
|
|
16
14
|
writeToFileByExtension,
|
|
17
15
|
getAndValidateFileExtension,
|
|
18
16
|
} from '../../utils/miscellaneous';
|
|
19
|
-
import {
|
|
17
|
+
import { isObject, isEmptyObject } from '../../utils/js-utils';
|
|
20
18
|
import {
|
|
19
|
+
OPENAPI3_COMPONENT,
|
|
20
|
+
COMPONENTS,
|
|
21
|
+
OPENAPI3_METHOD_NAMES,
|
|
22
|
+
OPENAPI3_COMPONENT_NAMES,
|
|
23
|
+
} from './types';
|
|
24
|
+
|
|
25
|
+
import type { OasRef } from '@redocly/openapi-core';
|
|
26
|
+
import type {
|
|
21
27
|
Definition,
|
|
22
28
|
Oas2Definition,
|
|
23
29
|
Oas3Schema,
|
|
@@ -26,13 +32,8 @@ import {
|
|
|
26
32
|
Oas3Components,
|
|
27
33
|
Oas3ComponentName,
|
|
28
34
|
ComponentsFiles,
|
|
29
|
-
|
|
35
|
+
RefObject,
|
|
30
36
|
Oas3PathItem,
|
|
31
|
-
OPENAPI3_COMPONENT,
|
|
32
|
-
COMPONENTS,
|
|
33
|
-
componentsPath,
|
|
34
|
-
OPENAPI3_METHOD_NAMES,
|
|
35
|
-
OPENAPI3_COMPONENT_NAMES,
|
|
36
37
|
Referenced,
|
|
37
38
|
} from './types';
|
|
38
39
|
|
|
@@ -93,8 +94,8 @@ function splitDefinition(
|
|
|
93
94
|
writeToFileByExtension(openapi, path.join(openapiDir, `openapi.${ext}`));
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
function
|
|
97
|
-
return node.startsWith(
|
|
97
|
+
export function startsWithComponents(node: string) {
|
|
98
|
+
return node.startsWith(`#/${COMPONENTS}/`);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
function isSupportedExtension(filename: string) {
|
|
@@ -144,33 +145,31 @@ function traverseDirectoryDeepCallback(
|
|
|
144
145
|
writeToFileByExtension(pathData, filename);
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
function crawl(object:
|
|
148
|
+
export function crawl(object: unknown, visitor: (node: Record<string, unknown>) => void) {
|
|
148
149
|
if (!isObject(object)) return;
|
|
150
|
+
|
|
151
|
+
visitor(object);
|
|
149
152
|
for (const key of Object.keys(object)) {
|
|
150
|
-
visitor(object, key);
|
|
151
153
|
crawl(object[key], visitor);
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
|
|
155
|
-
function replace$Refs(obj:
|
|
156
|
-
crawl(obj, (node:
|
|
157
|
-
if (node.$ref &&
|
|
158
|
-
replace(node, '$ref');
|
|
159
|
-
} else if (
|
|
160
|
-
node.discriminator &&
|
|
161
|
-
node.discriminator.mapping &&
|
|
162
|
-
isObject(node.discriminator.mapping)
|
|
163
|
-
) {
|
|
157
|
+
function replace$Refs(obj: unknown, relativeFrom: string, componentFiles = {} as ComponentsFiles) {
|
|
158
|
+
crawl(obj, (node: Record<string, unknown>) => {
|
|
159
|
+
if (node.$ref && typeof node.$ref === 'string' && startsWithComponents(node.$ref)) {
|
|
160
|
+
replace(node as RefObject, '$ref');
|
|
161
|
+
} else if (isObject(node.discriminator) && isObject(node.discriminator.mapping)) {
|
|
164
162
|
const { mapping } = node.discriminator;
|
|
165
163
|
for (const name of Object.keys(mapping)) {
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
const mappingPointer = mapping[name];
|
|
165
|
+
if (typeof mappingPointer === 'string' && startsWithComponents(mappingPointer)) {
|
|
166
|
+
replace(node.discriminator.mapping as RefObject, name);
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
}
|
|
171
170
|
});
|
|
172
171
|
|
|
173
|
-
function replace(node:
|
|
172
|
+
function replace(node: RefObject, key: string) {
|
|
174
173
|
const splittedNode = node[key].split('/');
|
|
175
174
|
const name = splittedNode.pop();
|
|
176
175
|
const groupName = splittedNode[2];
|
|
@@ -28,7 +28,7 @@ export type Definition = Oas3_1Definition | Oas3Definition | Oas2Definition;
|
|
|
28
28
|
export interface ComponentsFiles {
|
|
29
29
|
[schemas: string]: any;
|
|
30
30
|
}
|
|
31
|
-
export interface
|
|
31
|
+
export interface RefObject {
|
|
32
32
|
[$ref: string]: string;
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -36,8 +36,6 @@ export const COMPONENTS = 'components';
|
|
|
36
36
|
export const PATHS = 'paths';
|
|
37
37
|
export const WEBHOOKS = 'webhooks';
|
|
38
38
|
export const xWEBHOOKS = 'x-webhooks';
|
|
39
|
-
export const componentsPath = `#/${COMPONENTS}/`;
|
|
40
|
-
|
|
41
39
|
export enum OPENAPI3_METHOD {
|
|
42
40
|
get = 'get',
|
|
43
41
|
put = 'put',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import nodeFetch from 'node-fetch';
|
|
2
2
|
import AbortController from 'abort-controller';
|
|
3
|
+
import { getProxyAgent } from '@redocly/openapi-core';
|
|
3
4
|
|
|
4
5
|
const TIMEOUT = 3000;
|
|
5
6
|
|
|
@@ -10,7 +11,11 @@ export default async (url: string, options = {}) => {
|
|
|
10
11
|
controller.abort();
|
|
11
12
|
}, TIMEOUT);
|
|
12
13
|
|
|
13
|
-
const res = await nodeFetch(url, {
|
|
14
|
+
const res = await nodeFetch(url, {
|
|
15
|
+
signal: controller.signal,
|
|
16
|
+
...options,
|
|
17
|
+
agent: getProxyAgent(),
|
|
18
|
+
});
|
|
14
19
|
clearTimeout(timeout);
|
|
15
20
|
return res;
|
|
16
21
|
} catch (e) {
|
package/src/utils/js-utils.ts
CHANGED