@redocly/cli 1.0.0-beta.98 → 1.0.0-rc.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/bin/cli.js +1 -1
- package/lib/__mocks__/@redocly/openapi-core.d.ts +96 -0
- package/lib/__mocks__/@redocly/openapi-core.js +79 -0
- package/lib/__mocks__/documents.d.ts +92 -0
- package/lib/__mocks__/documents.js +63 -0
- package/lib/__mocks__/fs.d.ts +9 -0
- package/lib/__mocks__/fs.js +9 -0
- package/lib/__mocks__/perf_hooks.d.ts +4 -0
- package/lib/__mocks__/perf_hooks.js +6 -0
- package/lib/__mocks__/redoc.d.ts +7 -0
- package/lib/__mocks__/redoc.js +5 -0
- package/lib/__mocks__/utils.d.ts +26 -4
- package/lib/__mocks__/utils.js +8 -3
- package/lib/__tests__/commands/build-docs.test.d.ts +1 -0
- package/lib/__tests__/commands/build-docs.test.js +59 -0
- package/lib/__tests__/commands/bundle.test.js +66 -30
- package/lib/__tests__/commands/join.test.d.ts +1 -0
- package/lib/__tests__/commands/join.test.js +85 -0
- package/lib/__tests__/commands/lint.test.d.ts +1 -0
- package/lib/__tests__/commands/lint.test.js +149 -0
- package/lib/__tests__/commands/push-region.test.js +5 -4
- package/lib/__tests__/commands/push.test.js +254 -39
- package/lib/__tests__/fetch-with-timeout.test.d.ts +1 -0
- package/lib/__tests__/fetch-with-timeout.test.js +38 -0
- package/lib/__tests__/fixtures/config.d.ts +22 -0
- package/lib/__tests__/fixtures/config.js +24 -0
- package/lib/__tests__/utils.test.js +429 -1
- package/lib/__tests__/wrapper.test.d.ts +1 -0
- package/lib/__tests__/wrapper.test.js +57 -0
- package/lib/commands/build-docs/index.d.ts +3 -0
- package/lib/commands/build-docs/index.js +50 -0
- package/{src/commands/preview-docs/preview-server/default.hbs → lib/commands/build-docs/template.hbs} +2 -3
- package/lib/commands/build-docs/types.d.ts +23 -0
- package/lib/commands/build-docs/types.js +2 -0
- package/lib/commands/build-docs/utils.d.ts +7 -0
- package/lib/commands/build-docs/utils.js +99 -0
- package/lib/commands/bundle.d.ts +11 -12
- package/lib/commands/bundle.js +26 -24
- package/lib/commands/join.d.ts +12 -3
- package/lib/commands/join.js +295 -109
- package/lib/commands/lint.d.ts +11 -8
- package/lib/commands/lint.js +49 -19
- package/lib/commands/login.d.ts +5 -3
- package/lib/commands/login.js +2 -2
- package/lib/commands/preview-docs/index.d.ts +6 -6
- package/lib/commands/preview-docs/index.js +30 -20
- package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +1 -1
- package/lib/commands/preview-docs/preview-server/preview-server.js +5 -4
- package/lib/commands/preview-docs/preview-server/server.d.ts +1 -1
- package/lib/commands/push.d.ts +21 -10
- package/lib/commands/push.js +110 -63
- package/lib/commands/split/__tests__/index.test.js +23 -8
- package/lib/commands/split/index.d.ts +5 -3
- package/lib/commands/split/index.js +15 -24
- package/lib/commands/split/types.d.ts +11 -11
- package/lib/commands/split/types.js +19 -19
- package/lib/commands/stats.d.ts +7 -4
- package/lib/commands/stats.js +13 -12
- package/lib/fetch-with-timeout.d.ts +2 -0
- package/lib/fetch-with-timeout.js +30 -0
- package/lib/index.js +194 -40
- package/lib/js-utils.d.ts +1 -0
- package/lib/js-utils.js +9 -3
- package/lib/types.d.ts +17 -1
- package/lib/update-version-notifier.d.ts +3 -0
- package/lib/update-version-notifier.js +105 -0
- package/lib/utils.d.ts +39 -5
- package/lib/utils.js +273 -37
- package/lib/wrapper.d.ts +4 -0
- package/lib/wrapper.js +52 -0
- package/package.json +18 -8
- package/README.md +0 -39
- package/src/__mocks__/utils.ts +0 -11
- package/src/__tests__/commands/bundle.test.ts +0 -120
- package/src/__tests__/commands/push-region.test.ts +0 -51
- package/src/__tests__/commands/push.test.ts +0 -158
- package/src/__tests__/utils.test.ts +0 -50
- package/src/assert-node-version.ts +0 -8
- package/src/commands/bundle.ts +0 -178
- package/src/commands/join.ts +0 -488
- package/src/commands/lint.ts +0 -110
- package/src/commands/login.ts +0 -21
- package/src/commands/preview-docs/index.ts +0 -188
- package/src/commands/preview-docs/preview-server/hot.js +0 -42
- package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/src/commands/preview-docs/preview-server/preview-server.ts +0 -155
- package/src/commands/preview-docs/preview-server/server.ts +0 -91
- package/src/commands/push.ts +0 -357
- package/src/commands/split/__tests__/fixtures/spec.json +0 -70
- package/src/commands/split/__tests__/fixtures/webhooks.json +0 -88
- package/src/commands/split/__tests__/index.test.ts +0 -96
- package/src/commands/split/index.ts +0 -349
- package/src/commands/split/types.ts +0 -73
- package/src/commands/stats.ts +0 -115
- package/src/index.ts +0 -316
- package/src/js-utils.ts +0 -12
- package/src/types.ts +0 -13
- package/src/utils.ts +0 -300
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/bin/cli.js
CHANGED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { Document } from '@redocly/openapi-core';
|
|
3
|
+
export declare const __redoclyClient: {
|
|
4
|
+
isAuthorizedWithRedocly: jest.Mock<any, any>;
|
|
5
|
+
isAuthorizedWithRedoclyByRegion: jest.Mock<any, any>;
|
|
6
|
+
login: jest.Mock<any, any>;
|
|
7
|
+
registryApi: {
|
|
8
|
+
setAccessTokens: jest.Mock<any, any>;
|
|
9
|
+
authStatus: jest.Mock<any, any>;
|
|
10
|
+
prepareFileUpload: jest.Mock<any, any>;
|
|
11
|
+
pushApi: jest.Mock<any, any>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const RedoclyClient: jest.Mock<{
|
|
15
|
+
isAuthorizedWithRedocly: jest.Mock<any, any>;
|
|
16
|
+
isAuthorizedWithRedoclyByRegion: jest.Mock<any, any>;
|
|
17
|
+
login: jest.Mock<any, any>;
|
|
18
|
+
registryApi: {
|
|
19
|
+
setAccessTokens: jest.Mock<any, any>;
|
|
20
|
+
authStatus: jest.Mock<any, any>;
|
|
21
|
+
prepareFileUpload: jest.Mock<any, any>;
|
|
22
|
+
pushApi: jest.Mock<any, any>;
|
|
23
|
+
};
|
|
24
|
+
}, []>;
|
|
25
|
+
export declare const loadConfig: jest.Mock<{
|
|
26
|
+
configFile: null;
|
|
27
|
+
styleguide: {
|
|
28
|
+
addIgnore: jest.Mock<any, any>;
|
|
29
|
+
skipRules: jest.Mock<any, any>;
|
|
30
|
+
skipPreprocessors: jest.Mock<any, any>;
|
|
31
|
+
saveIgnore: jest.Mock<any, any>;
|
|
32
|
+
skipDecorators: jest.Mock<any, any>;
|
|
33
|
+
ignore: null;
|
|
34
|
+
decorators: {
|
|
35
|
+
oas2: {};
|
|
36
|
+
oas3_0: {};
|
|
37
|
+
oas3_1: {};
|
|
38
|
+
};
|
|
39
|
+
preprocessors: {
|
|
40
|
+
oas2: {};
|
|
41
|
+
oas3_0: {};
|
|
42
|
+
oas3_1: {};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}, []>;
|
|
46
|
+
export declare const getMergedConfig: jest.Mock<any, any>;
|
|
47
|
+
export declare const lint: jest.Mock<any, any>;
|
|
48
|
+
export declare const bundle: jest.Mock<{
|
|
49
|
+
bundle: {
|
|
50
|
+
parsed: null;
|
|
51
|
+
};
|
|
52
|
+
problems: null;
|
|
53
|
+
}, []>;
|
|
54
|
+
export declare const getTotals: jest.Mock<{
|
|
55
|
+
errors: number;
|
|
56
|
+
}, []>;
|
|
57
|
+
export declare const formatProblems: jest.Mock<any, any>;
|
|
58
|
+
export declare const slash: jest.Mock<any, any>;
|
|
59
|
+
export declare const findConfig: jest.Mock<any, any>;
|
|
60
|
+
export declare const doesYamlFileExist: jest.Mock<any, any>;
|
|
61
|
+
export declare const bundleDocument: jest.Mock<Promise<{
|
|
62
|
+
problems: {};
|
|
63
|
+
}>, []>;
|
|
64
|
+
export declare const detectOpenAPI: jest.Mock<any, any>;
|
|
65
|
+
export declare const isAbsoluteUrl: jest.Mock<any, any>;
|
|
66
|
+
export declare class BaseResolver {
|
|
67
|
+
cache: Map<string, Promise<Document | ResolveError>>;
|
|
68
|
+
getFiles: jest.Mock<any, any>;
|
|
69
|
+
resolveExternalRef: jest.Mock<any, any>;
|
|
70
|
+
loadExternalRef: typeof jest.fn;
|
|
71
|
+
parseDocument: jest.Mock<any, any>;
|
|
72
|
+
resolveDocument: jest.Mock<any, any>;
|
|
73
|
+
}
|
|
74
|
+
export declare class ResolveError extends Error {
|
|
75
|
+
originalError: Error;
|
|
76
|
+
constructor(originalError: Error);
|
|
77
|
+
}
|
|
78
|
+
export declare class YamlParseError extends Error {
|
|
79
|
+
originalError: Error;
|
|
80
|
+
constructor(originalError: Error);
|
|
81
|
+
}
|
|
82
|
+
export declare enum OasVersion {
|
|
83
|
+
Version2 = "oas2",
|
|
84
|
+
Version3_0 = "oas3_0",
|
|
85
|
+
Version3_1 = "oas3_1"
|
|
86
|
+
}
|
|
87
|
+
export declare enum Oas3Operations {
|
|
88
|
+
get = "get",
|
|
89
|
+
put = "put",
|
|
90
|
+
post = "post",
|
|
91
|
+
delete = "delete",
|
|
92
|
+
options = "options",
|
|
93
|
+
head = "head",
|
|
94
|
+
patch = "patch",
|
|
95
|
+
trace = "trace"
|
|
96
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Oas3Operations = exports.OasVersion = exports.YamlParseError = exports.ResolveError = exports.BaseResolver = exports.isAbsoluteUrl = exports.detectOpenAPI = 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
|
+
const config_1 = require("./../../__tests__/fixtures/config");
|
|
5
|
+
const documents_1 = require("../documents");
|
|
6
|
+
exports.__redoclyClient = {
|
|
7
|
+
isAuthorizedWithRedocly: jest.fn().mockResolvedValue(true),
|
|
8
|
+
isAuthorizedWithRedoclyByRegion: jest.fn().mockResolvedValue(true),
|
|
9
|
+
login: jest.fn(),
|
|
10
|
+
registryApi: {
|
|
11
|
+
setAccessTokens: jest.fn(),
|
|
12
|
+
authStatus: jest.fn(),
|
|
13
|
+
prepareFileUpload: jest.fn().mockResolvedValue({
|
|
14
|
+
signedUploadUrl: 'signedUploadUrl',
|
|
15
|
+
filePath: 'filePath',
|
|
16
|
+
}),
|
|
17
|
+
pushApi: jest.fn(),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
exports.RedoclyClient = jest.fn(() => exports.__redoclyClient);
|
|
21
|
+
exports.loadConfig = jest.fn(() => config_1.ConfigFixture);
|
|
22
|
+
exports.getMergedConfig = jest.fn();
|
|
23
|
+
exports.lint = jest.fn();
|
|
24
|
+
exports.bundle = jest.fn(() => ({ bundle: { parsed: null }, problems: null }));
|
|
25
|
+
exports.getTotals = jest.fn(() => ({ errors: 0 }));
|
|
26
|
+
exports.formatProblems = jest.fn();
|
|
27
|
+
exports.slash = jest.fn();
|
|
28
|
+
exports.findConfig = jest.fn();
|
|
29
|
+
exports.doesYamlFileExist = jest.fn();
|
|
30
|
+
exports.bundleDocument = jest.fn(() => Promise.resolve({ problems: {} }));
|
|
31
|
+
exports.detectOpenAPI = jest.fn();
|
|
32
|
+
exports.isAbsoluteUrl = jest.fn();
|
|
33
|
+
class BaseResolver {
|
|
34
|
+
constructor() {
|
|
35
|
+
this.cache = new Map();
|
|
36
|
+
this.getFiles = jest.fn();
|
|
37
|
+
this.resolveExternalRef = jest.fn();
|
|
38
|
+
this.loadExternalRef = jest.fn;
|
|
39
|
+
this.parseDocument = jest.fn();
|
|
40
|
+
this.resolveDocument = jest
|
|
41
|
+
.fn()
|
|
42
|
+
.mockImplementationOnce(() => Promise.resolve({ source: { absoluteRef: 'ref' }, parsed: documents_1.firstDocument }))
|
|
43
|
+
.mockImplementationOnce(() => Promise.resolve({ source: { absoluteRef: 'ref' }, parsed: documents_1.secondDocument }));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.BaseResolver = BaseResolver;
|
|
47
|
+
class ResolveError extends Error {
|
|
48
|
+
constructor(originalError) {
|
|
49
|
+
super(originalError.message);
|
|
50
|
+
this.originalError = originalError;
|
|
51
|
+
Object.setPrototypeOf(this, ResolveError.prototype);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ResolveError = ResolveError;
|
|
55
|
+
class YamlParseError extends Error {
|
|
56
|
+
constructor(originalError) {
|
|
57
|
+
super(originalError.message);
|
|
58
|
+
this.originalError = originalError;
|
|
59
|
+
Object.setPrototypeOf(this, YamlParseError.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.YamlParseError = YamlParseError;
|
|
63
|
+
var OasVersion;
|
|
64
|
+
(function (OasVersion) {
|
|
65
|
+
OasVersion["Version2"] = "oas2";
|
|
66
|
+
OasVersion["Version3_0"] = "oas3_0";
|
|
67
|
+
OasVersion["Version3_1"] = "oas3_1";
|
|
68
|
+
})(OasVersion = exports.OasVersion || (exports.OasVersion = {}));
|
|
69
|
+
var Oas3Operations;
|
|
70
|
+
(function (Oas3Operations) {
|
|
71
|
+
Oas3Operations["get"] = "get";
|
|
72
|
+
Oas3Operations["put"] = "put";
|
|
73
|
+
Oas3Operations["post"] = "post";
|
|
74
|
+
Oas3Operations["delete"] = "delete";
|
|
75
|
+
Oas3Operations["options"] = "options";
|
|
76
|
+
Oas3Operations["head"] = "head";
|
|
77
|
+
Oas3Operations["patch"] = "patch";
|
|
78
|
+
Oas3Operations["trace"] = "trace";
|
|
79
|
+
})(Oas3Operations = exports.Oas3Operations || (exports.Oas3Operations = {}));
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export declare const firstDocument: {
|
|
2
|
+
openapi: string;
|
|
3
|
+
servers: {
|
|
4
|
+
url: string;
|
|
5
|
+
}[];
|
|
6
|
+
info: {
|
|
7
|
+
description: string;
|
|
8
|
+
version: string;
|
|
9
|
+
title: string;
|
|
10
|
+
termsOfService: string;
|
|
11
|
+
license: {
|
|
12
|
+
name: string;
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
paths: {
|
|
17
|
+
'/GETUser/{userId}': {
|
|
18
|
+
summary: string;
|
|
19
|
+
description: string;
|
|
20
|
+
servers: ({
|
|
21
|
+
url: string;
|
|
22
|
+
description?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
url: string;
|
|
25
|
+
description: string;
|
|
26
|
+
})[];
|
|
27
|
+
get: {
|
|
28
|
+
tags: string[];
|
|
29
|
+
summary: string;
|
|
30
|
+
description: string;
|
|
31
|
+
operationId: string;
|
|
32
|
+
servers: {
|
|
33
|
+
url: string;
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
36
|
+
parameters: {
|
|
37
|
+
name: string;
|
|
38
|
+
in: string;
|
|
39
|
+
schema: {
|
|
40
|
+
description: string;
|
|
41
|
+
};
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
components: {};
|
|
46
|
+
};
|
|
47
|
+
export declare const secondDocument: {
|
|
48
|
+
openapi: string;
|
|
49
|
+
servers: {
|
|
50
|
+
url: string;
|
|
51
|
+
}[];
|
|
52
|
+
info: {
|
|
53
|
+
description: string;
|
|
54
|
+
version: string;
|
|
55
|
+
title: string;
|
|
56
|
+
termsOfService: string;
|
|
57
|
+
license: {
|
|
58
|
+
name: string;
|
|
59
|
+
url: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
post: {
|
|
63
|
+
'/GETUser/{userId}': {
|
|
64
|
+
summary: string;
|
|
65
|
+
description: string;
|
|
66
|
+
servers: ({
|
|
67
|
+
url: string;
|
|
68
|
+
description?: undefined;
|
|
69
|
+
} | {
|
|
70
|
+
url: string;
|
|
71
|
+
description: string;
|
|
72
|
+
})[];
|
|
73
|
+
get: {
|
|
74
|
+
tags: string[];
|
|
75
|
+
summary: string;
|
|
76
|
+
description: string;
|
|
77
|
+
operationId: string;
|
|
78
|
+
servers: {
|
|
79
|
+
url: string;
|
|
80
|
+
}[];
|
|
81
|
+
};
|
|
82
|
+
parameters: {
|
|
83
|
+
name: string;
|
|
84
|
+
in: string;
|
|
85
|
+
schema: {
|
|
86
|
+
description: string;
|
|
87
|
+
};
|
|
88
|
+
}[];
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
components: {};
|
|
92
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.secondDocument = exports.firstDocument = void 0;
|
|
4
|
+
exports.firstDocument = {
|
|
5
|
+
openapi: '3.0.0',
|
|
6
|
+
servers: [{ url: 'http://localhost:8080' }],
|
|
7
|
+
info: {
|
|
8
|
+
description: 'example test',
|
|
9
|
+
version: '1.0.0',
|
|
10
|
+
title: 'Swagger Petstore',
|
|
11
|
+
termsOfService: 'http://swagger.io/terms/',
|
|
12
|
+
license: {
|
|
13
|
+
name: 'Apache 2.0',
|
|
14
|
+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
paths: {
|
|
18
|
+
'/GETUser/{userId}': {
|
|
19
|
+
summary: 'get user by id',
|
|
20
|
+
description: 'user info',
|
|
21
|
+
servers: [{ url: '/user' }, { url: '/pet', description: 'pet server' }],
|
|
22
|
+
get: {
|
|
23
|
+
tags: ['pet'],
|
|
24
|
+
summary: 'Find pet by ID',
|
|
25
|
+
description: 'Returns a single pet',
|
|
26
|
+
operationId: 'getPetById',
|
|
27
|
+
servers: [{ url: '/pet' }],
|
|
28
|
+
},
|
|
29
|
+
parameters: [{ name: 'param1', in: 'header', schema: { description: 'string' } }],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
components: {},
|
|
33
|
+
};
|
|
34
|
+
exports.secondDocument = {
|
|
35
|
+
openapi: '3.0.0',
|
|
36
|
+
servers: [{ url: 'http://localhost:8080' }],
|
|
37
|
+
info: {
|
|
38
|
+
description: 'example test',
|
|
39
|
+
version: '1.0.0',
|
|
40
|
+
title: 'Swagger Petstore',
|
|
41
|
+
termsOfService: 'http://swagger.io/terms/',
|
|
42
|
+
license: {
|
|
43
|
+
name: 'Apache 2.0',
|
|
44
|
+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
post: {
|
|
48
|
+
'/GETUser/{userId}': {
|
|
49
|
+
summary: 'get user',
|
|
50
|
+
description: 'user information',
|
|
51
|
+
servers: [{ url: '/user' }, { url: '/pet', description: '' }],
|
|
52
|
+
get: {
|
|
53
|
+
tags: ['pet'],
|
|
54
|
+
summary: 'Find pet by ID',
|
|
55
|
+
description: 'Returns a single pet',
|
|
56
|
+
operationId: 'getPetById',
|
|
57
|
+
servers: [{ url: '/pet' }],
|
|
58
|
+
},
|
|
59
|
+
parameters: [{ name: 'param1', in: 'header', schema: { description: 'string' } }],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
components: {},
|
|
63
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
export declare const existsSync: jest.Mock<any, any>;
|
|
3
|
+
export declare const readFileSync: jest.Mock<string, []>;
|
|
4
|
+
export declare const statSync: jest.Mock<{
|
|
5
|
+
size: number;
|
|
6
|
+
}, []>;
|
|
7
|
+
export declare const createReadStream: jest.Mock<any, any>;
|
|
8
|
+
export declare const writeFileSync: jest.Mock<any, any>;
|
|
9
|
+
export declare const mkdirSync: jest.Mock<any, any>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mkdirSync = exports.writeFileSync = exports.createReadStream = exports.statSync = exports.readFileSync = exports.existsSync = void 0;
|
|
4
|
+
exports.existsSync = jest.fn();
|
|
5
|
+
exports.readFileSync = jest.fn(() => '');
|
|
6
|
+
exports.statSync = jest.fn(() => ({ size: 0 }));
|
|
7
|
+
exports.createReadStream = jest.fn();
|
|
8
|
+
exports.writeFileSync = jest.fn();
|
|
9
|
+
exports.mkdirSync = jest.fn();
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStore = exports.loadAndBundleSpec = void 0;
|
|
4
|
+
exports.loadAndBundleSpec = jest.fn(() => Promise.resolve({ openapi: '3.0.0' }));
|
|
5
|
+
exports.createStore = jest.fn(() => Promise.resolve({ toJS: jest.fn(() => '{}') }));
|
package/lib/__mocks__/utils.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const getTotals: jest.Mock<{
|
|
4
|
-
errors: number;
|
|
5
|
-
}, []>;
|
|
2
|
+
export declare const getFallbackApisOrExit: jest.Mock<any, [entrypoints: any]>;
|
|
6
3
|
export declare const dumpBundle: jest.Mock<string, []>;
|
|
7
4
|
export declare const slash: jest.Mock<any, any>;
|
|
8
5
|
export declare const pluralize: jest.Mock<any, any>;
|
|
@@ -15,3 +12,28 @@ export declare const getOutputFileName: jest.Mock<{
|
|
|
15
12
|
ext: string;
|
|
16
13
|
}, []>;
|
|
17
14
|
export declare const handleError: jest.Mock<any, any>;
|
|
15
|
+
export declare const exitWithError: jest.Mock<any, any>;
|
|
16
|
+
export declare const writeYaml: jest.Mock<any, any>;
|
|
17
|
+
export declare const loadConfigAndHandleErrors: jest.Mock<{
|
|
18
|
+
configFile: null;
|
|
19
|
+
styleguide: {
|
|
20
|
+
addIgnore: jest.Mock<any, any>;
|
|
21
|
+
skipRules: jest.Mock<any, any>;
|
|
22
|
+
skipPreprocessors: jest.Mock<any, any>;
|
|
23
|
+
saveIgnore: jest.Mock<any, any>;
|
|
24
|
+
skipDecorators: jest.Mock<any, any>;
|
|
25
|
+
ignore: null;
|
|
26
|
+
decorators: {
|
|
27
|
+
oas2: {};
|
|
28
|
+
oas3_0: {};
|
|
29
|
+
oas3_1: {};
|
|
30
|
+
};
|
|
31
|
+
preprocessors: {
|
|
32
|
+
oas2: {};
|
|
33
|
+
oas3_0: {};
|
|
34
|
+
oas3_1: {};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}, []>;
|
|
38
|
+
export declare const checkIfRulesetExist: jest.Mock<any, any>;
|
|
39
|
+
export declare const sortTopLevelKeysForOas: jest.Mock<any, [document: any]>;
|
package/lib/__mocks__/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleError = exports.getOutputFileName = exports.printLintTotals = exports.printUnusedWarnings = exports.printExecutionTime = exports.getExecutionTime = exports.pluralize = exports.slash = exports.dumpBundle = exports.
|
|
4
|
-
|
|
5
|
-
exports.
|
|
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;
|
|
4
|
+
const config_1 = require("../__tests__/fixtures/config");
|
|
5
|
+
exports.getFallbackApisOrExit = jest.fn((entrypoints) => entrypoints.map((path) => ({ path })));
|
|
6
6
|
exports.dumpBundle = jest.fn(() => '');
|
|
7
7
|
exports.slash = jest.fn();
|
|
8
8
|
exports.pluralize = jest.fn();
|
|
@@ -12,3 +12,8 @@ exports.printUnusedWarnings = jest.fn();
|
|
|
12
12
|
exports.printLintTotals = jest.fn();
|
|
13
13
|
exports.getOutputFileName = jest.fn(() => ({ outputFile: 'test.yaml', ext: 'yaml' }));
|
|
14
14
|
exports.handleError = jest.fn();
|
|
15
|
+
exports.exitWithError = jest.fn();
|
|
16
|
+
exports.writeYaml = jest.fn();
|
|
17
|
+
exports.loadConfigAndHandleErrors = jest.fn(() => config_1.ConfigFixture);
|
|
18
|
+
exports.checkIfRulesetExist = jest.fn();
|
|
19
|
+
exports.sortTopLevelKeysForOas = jest.fn((document) => document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const redoc_1 = require("redoc");
|
|
13
|
+
const server_1 = require("react-dom/server");
|
|
14
|
+
const build_docs_1 = require("../../commands/build-docs");
|
|
15
|
+
const utils_1 = require("../../commands/build-docs/utils");
|
|
16
|
+
const utils_2 = require("../../utils");
|
|
17
|
+
jest.mock('redoc');
|
|
18
|
+
jest.mock('fs');
|
|
19
|
+
jest.mock('../../utils');
|
|
20
|
+
const config = {
|
|
21
|
+
output: '',
|
|
22
|
+
title: 'Test',
|
|
23
|
+
disableGoogleFont: false,
|
|
24
|
+
templateFileName: '',
|
|
25
|
+
templateOptions: {},
|
|
26
|
+
redocOptions: {},
|
|
27
|
+
};
|
|
28
|
+
jest.mock('react-dom/server', () => ({
|
|
29
|
+
renderToString: jest.fn(),
|
|
30
|
+
}));
|
|
31
|
+
jest.mock('handlebars', () => ({
|
|
32
|
+
compile: jest.fn(() => jest.fn(() => '<html></html>')),
|
|
33
|
+
}));
|
|
34
|
+
jest.mock('mkdirp', () => ({
|
|
35
|
+
sync: jest.fn(),
|
|
36
|
+
}));
|
|
37
|
+
describe('build-docs', () => {
|
|
38
|
+
it('should return correct html and call function for ssr', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const result = yield utils_1.getPageHTML({}, '../some-path/openapi.yaml', Object.assign(Object.assign({}, config), { redocCurrentVersion: '2.0.0' }));
|
|
40
|
+
expect(server_1.renderToString).toBeCalledTimes(1);
|
|
41
|
+
expect(redoc_1.createStore).toBeCalledTimes(1);
|
|
42
|
+
expect(result).toBe('<html></html>');
|
|
43
|
+
}));
|
|
44
|
+
it('should work correctly when calling handlerBuildCommand', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const processExitMock = jest.spyOn(process, 'exit').mockImplementation();
|
|
46
|
+
yield build_docs_1.handlerBuildCommand({
|
|
47
|
+
o: '',
|
|
48
|
+
title: 'test',
|
|
49
|
+
disableGoogleFont: false,
|
|
50
|
+
template: '',
|
|
51
|
+
templateOptions: {},
|
|
52
|
+
theme: { openapi: {} },
|
|
53
|
+
api: '../some-path/openapi.yaml',
|
|
54
|
+
}, {});
|
|
55
|
+
expect(redoc_1.loadAndBundleSpec).toBeCalledTimes(1);
|
|
56
|
+
expect(utils_2.getFallbackApisOrExit).toBeCalledTimes(1);
|
|
57
|
+
expect(processExitMock).toBeCalledTimes(0);
|
|
58
|
+
}));
|
|
59
|
+
});
|
|
@@ -11,9 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
13
13
|
const bundle_1 = require("../../commands/bundle");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
const wrapper_1 = require("../../wrapper");
|
|
14
16
|
jest.mock('@redocly/openapi-core');
|
|
15
17
|
jest.mock('../../utils');
|
|
16
|
-
openapi_core_1.getMergedConfig.mockImplementation(config => config);
|
|
18
|
+
openapi_core_1.getMergedConfig.mockImplementation((config) => config);
|
|
17
19
|
describe('bundle', () => {
|
|
18
20
|
let processExitMock;
|
|
19
21
|
let exitCb;
|
|
@@ -28,65 +30,99 @@ describe('bundle', () => {
|
|
|
28
30
|
afterEach(() => {
|
|
29
31
|
openapi_core_1.lint.mockClear();
|
|
30
32
|
openapi_core_1.bundle.mockClear();
|
|
31
|
-
openapi_core_1.getTotals.
|
|
33
|
+
openapi_core_1.getTotals.mockReset();
|
|
32
34
|
});
|
|
33
35
|
it('bundles definitions w/o linting', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
const
|
|
35
|
-
yield bundle_1.handleBundle({
|
|
36
|
-
|
|
36
|
+
const apis = ['foo.yaml', 'bar.yaml'];
|
|
37
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
38
|
+
apis,
|
|
37
39
|
ext: 'yaml',
|
|
38
40
|
format: 'codeframe',
|
|
39
|
-
}
|
|
41
|
+
});
|
|
40
42
|
expect(openapi_core_1.lint).toBeCalledTimes(0);
|
|
41
|
-
expect(openapi_core_1.bundle).toBeCalledTimes(
|
|
43
|
+
expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
|
|
42
44
|
}));
|
|
43
45
|
it('exits with code 0 when bundles definitions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
const
|
|
45
|
-
yield bundle_1.handleBundle({
|
|
46
|
-
|
|
46
|
+
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
47
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
48
|
+
apis,
|
|
47
49
|
ext: 'yaml',
|
|
48
50
|
format: 'codeframe',
|
|
49
|
-
}
|
|
50
|
-
exitCb === null || exitCb === void 0 ? void 0 : exitCb();
|
|
51
|
+
});
|
|
52
|
+
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
51
53
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
52
54
|
}));
|
|
53
55
|
it('bundles definitions w/ linting', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
57
|
+
openapi_core_1.getTotals.mockReturnValue({
|
|
58
|
+
errors: 0,
|
|
59
|
+
warnings: 0,
|
|
60
|
+
ignored: 0,
|
|
61
|
+
});
|
|
62
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
63
|
+
apis,
|
|
57
64
|
ext: 'yaml',
|
|
58
65
|
format: 'codeframe',
|
|
59
66
|
lint: true,
|
|
60
|
-
}
|
|
61
|
-
expect(openapi_core_1.lint).toBeCalledTimes(
|
|
62
|
-
expect(openapi_core_1.bundle).toBeCalledTimes(
|
|
67
|
+
});
|
|
68
|
+
expect(openapi_core_1.lint).toBeCalledTimes(apis.length);
|
|
69
|
+
expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
|
|
63
70
|
}));
|
|
64
71
|
it('exits with code 0 when bundles definitions w/linting w/o errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
const
|
|
66
|
-
yield bundle_1.handleBundle({
|
|
67
|
-
|
|
72
|
+
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
73
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
74
|
+
apis,
|
|
68
75
|
ext: 'yaml',
|
|
69
76
|
format: 'codeframe',
|
|
70
77
|
lint: true,
|
|
71
|
-
}
|
|
72
|
-
exitCb === null || exitCb === void 0 ? void 0 : exitCb();
|
|
78
|
+
});
|
|
79
|
+
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
73
80
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
74
81
|
}));
|
|
75
82
|
it('exits with code 1 when bundles definitions w/linting w/errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
-
const
|
|
83
|
+
const apis = ['foo.yaml'];
|
|
77
84
|
openapi_core_1.getTotals.mockReturnValue({
|
|
78
85
|
errors: 1,
|
|
79
86
|
warnings: 0,
|
|
80
|
-
ignored: 0
|
|
87
|
+
ignored: 0,
|
|
81
88
|
});
|
|
82
|
-
yield bundle_1.handleBundle({
|
|
83
|
-
|
|
89
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
90
|
+
apis,
|
|
84
91
|
ext: 'yaml',
|
|
85
92
|
format: 'codeframe',
|
|
86
93
|
lint: true,
|
|
87
|
-
}
|
|
88
|
-
expect(openapi_core_1.lint).toBeCalledTimes(
|
|
89
|
-
exitCb === null || exitCb === void 0 ? void 0 : exitCb();
|
|
94
|
+
});
|
|
95
|
+
expect(openapi_core_1.lint).toBeCalledTimes(apis.length);
|
|
96
|
+
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
90
97
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
91
98
|
}));
|
|
99
|
+
it('handleError is called when bundles an invalid definition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
const apis = ['invalid.json'];
|
|
101
|
+
openapi_core_1.bundle.mockImplementationOnce(() => {
|
|
102
|
+
throw new Error('Invalid definition');
|
|
103
|
+
});
|
|
104
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
105
|
+
apis,
|
|
106
|
+
ext: 'json',
|
|
107
|
+
format: 'codeframe',
|
|
108
|
+
lint: false,
|
|
109
|
+
});
|
|
110
|
+
expect(utils_1.handleError).toHaveBeenCalledTimes(1);
|
|
111
|
+
expect(utils_1.handleError).toHaveBeenCalledWith(new Error('Invalid definition'), 'invalid.json');
|
|
112
|
+
}));
|
|
113
|
+
it("handleError isn't called when bundles a valid definition", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
const apis = ['foo.yaml'];
|
|
115
|
+
openapi_core_1.getTotals.mockReturnValue({
|
|
116
|
+
errors: 0,
|
|
117
|
+
warnings: 0,
|
|
118
|
+
ignored: 0,
|
|
119
|
+
});
|
|
120
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
121
|
+
apis,
|
|
122
|
+
ext: 'yaml',
|
|
123
|
+
format: 'codeframe',
|
|
124
|
+
lint: false,
|
|
125
|
+
});
|
|
126
|
+
expect(utils_1.handleError).toHaveBeenCalledTimes(0);
|
|
127
|
+
}));
|
|
92
128
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|