@redocly/cli 1.0.0-beta.99 → 1.0.0-rc.2

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.
Files changed (103) hide show
  1. package/README.md +83 -22
  2. package/bin/cli.js +1 -1
  3. package/lib/__mocks__/@redocly/openapi-core.d.ts +53 -1
  4. package/lib/__mocks__/@redocly/openapi-core.js +56 -5
  5. package/lib/__mocks__/documents.d.ts +92 -0
  6. package/lib/__mocks__/documents.js +63 -0
  7. package/lib/__mocks__/fs.d.ts +2 -0
  8. package/lib/__mocks__/fs.js +3 -1
  9. package/lib/__mocks__/perf_hooks.d.ts +4 -0
  10. package/lib/__mocks__/perf_hooks.js +6 -0
  11. package/lib/__mocks__/redoc.d.ts +7 -0
  12. package/lib/__mocks__/redoc.js +5 -0
  13. package/lib/__mocks__/utils.d.ts +26 -4
  14. package/lib/__mocks__/utils.js +8 -3
  15. package/lib/__tests__/commands/build-docs.test.d.ts +1 -0
  16. package/lib/__tests__/commands/build-docs.test.js +59 -0
  17. package/lib/__tests__/commands/bundle.test.js +66 -30
  18. package/lib/__tests__/commands/join.test.d.ts +1 -0
  19. package/lib/__tests__/commands/join.test.js +85 -0
  20. package/lib/__tests__/commands/lint.test.d.ts +1 -0
  21. package/lib/__tests__/commands/lint.test.js +149 -0
  22. package/lib/__tests__/commands/push-region.test.js +5 -4
  23. package/lib/__tests__/commands/push.test.js +254 -39
  24. package/lib/__tests__/fetch-with-timeout.test.d.ts +1 -0
  25. package/lib/__tests__/fetch-with-timeout.test.js +38 -0
  26. package/lib/__tests__/fixtures/config.d.ts +22 -0
  27. package/lib/__tests__/fixtures/config.js +24 -0
  28. package/lib/__tests__/utils.test.js +429 -1
  29. package/lib/__tests__/wrapper.test.d.ts +1 -0
  30. package/lib/__tests__/wrapper.test.js +57 -0
  31. package/lib/commands/build-docs/index.d.ts +3 -0
  32. package/lib/commands/build-docs/index.js +50 -0
  33. package/{src/commands/preview-docs/preview-server/default.hbs → lib/commands/build-docs/template.hbs} +2 -3
  34. package/lib/commands/build-docs/types.d.ts +23 -0
  35. package/lib/commands/build-docs/types.js +2 -0
  36. package/lib/commands/build-docs/utils.d.ts +7 -0
  37. package/lib/commands/build-docs/utils.js +99 -0
  38. package/lib/commands/bundle.d.ts +10 -12
  39. package/lib/commands/bundle.js +25 -24
  40. package/lib/commands/join.d.ts +12 -3
  41. package/lib/commands/join.js +295 -109
  42. package/lib/commands/lint.d.ts +11 -8
  43. package/lib/commands/lint.js +49 -19
  44. package/lib/commands/login.d.ts +5 -3
  45. package/lib/commands/login.js +2 -2
  46. package/lib/commands/preview-docs/index.d.ts +6 -6
  47. package/lib/commands/preview-docs/index.js +30 -20
  48. package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +1 -1
  49. package/lib/commands/preview-docs/preview-server/preview-server.js +5 -4
  50. package/lib/commands/preview-docs/preview-server/server.d.ts +1 -1
  51. package/lib/commands/push.d.ts +21 -10
  52. package/lib/commands/push.js +110 -63
  53. package/lib/commands/split/__tests__/index.test.js +10 -8
  54. package/lib/commands/split/index.d.ts +5 -3
  55. package/lib/commands/split/index.js +15 -24
  56. package/lib/commands/split/types.d.ts +11 -11
  57. package/lib/commands/split/types.js +19 -19
  58. package/lib/commands/stats.d.ts +7 -4
  59. package/lib/commands/stats.js +13 -12
  60. package/lib/fetch-with-timeout.d.ts +2 -0
  61. package/lib/fetch-with-timeout.js +30 -0
  62. package/lib/index.js +194 -40
  63. package/lib/js-utils.d.ts +1 -0
  64. package/lib/js-utils.js +9 -3
  65. package/lib/types.d.ts +17 -1
  66. package/lib/update-version-notifier.d.ts +3 -0
  67. package/lib/update-version-notifier.js +105 -0
  68. package/lib/utils.d.ts +38 -5
  69. package/lib/utils.js +270 -41
  70. package/lib/wrapper.d.ts +4 -0
  71. package/lib/wrapper.js +52 -0
  72. package/package.json +18 -8
  73. package/src/__mocks__/@redocly/openapi-core.ts +0 -26
  74. package/src/__mocks__/fs.ts +0 -4
  75. package/src/__mocks__/utils.ts +0 -11
  76. package/src/__tests__/commands/bundle.test.ts +0 -120
  77. package/src/__tests__/commands/push-region.test.ts +0 -51
  78. package/src/__tests__/commands/push.test.ts +0 -158
  79. package/src/__tests__/utils.test.ts +0 -50
  80. package/src/assert-node-version.ts +0 -8
  81. package/src/commands/bundle.ts +0 -180
  82. package/src/commands/join.ts +0 -488
  83. package/src/commands/lint.ts +0 -110
  84. package/src/commands/login.ts +0 -21
  85. package/src/commands/preview-docs/index.ts +0 -188
  86. package/src/commands/preview-docs/preview-server/hot.js +0 -42
  87. package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  88. package/src/commands/preview-docs/preview-server/preview-server.ts +0 -155
  89. package/src/commands/preview-docs/preview-server/server.ts +0 -91
  90. package/src/commands/push.ts +0 -357
  91. package/src/commands/split/__tests__/fixtures/samples.json +0 -61
  92. package/src/commands/split/__tests__/fixtures/spec.json +0 -70
  93. package/src/commands/split/__tests__/fixtures/webhooks.json +0 -88
  94. package/src/commands/split/__tests__/index.test.ts +0 -117
  95. package/src/commands/split/index.ts +0 -349
  96. package/src/commands/split/types.ts +0 -73
  97. package/src/commands/stats.ts +0 -115
  98. package/src/index.ts +0 -316
  99. package/src/js-utils.ts +0 -12
  100. package/src/types.ts +0 -13
  101. package/src/utils.ts +0 -307
  102. package/tsconfig.json +0 -9
  103. package/tsconfig.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -1,39 +1,100 @@
1
- # Redocly CLI toolset
1
+ # Redocly CLI
2
2
 
3
- Redocly CLI toolbox with rich validation and bundling features.
3
+ Command-line utility from [@Redocly](https://redocly.com) with OpenAPI superpowers. Build, manage and quality-check OpenAPI descriptions, configure and execute API governance, and publish beautiful API documentation. Supports OpenAPI 3.1, 3.0 and OpenAPI 2.0 (legacy Swagger format).
4
4
 
5
+ ![build and test](https://github.com/redocly/redocly-cli/actions/workflows/tests.yaml/badge.svg)
5
6
  ![npm (scoped)](https://img.shields.io/npm/v/@redocly/cli)
6
7
  ![NPM](https://img.shields.io/npm/l/@redocly/cli)
7
8
 
8
9
  ![OpenAPI 3 CLI toolset](./media/redocly-cli.gif)
9
10
 
10
- ## Features
11
+ ## Usage
11
12
 
12
- Currently, @redocly/cli supports these features:
13
+ ### Node
13
14
 
14
- - [x] Multifile validation. No need to bundle your file before validation.
15
- - [x] Lightning-fast validation. Lint a 1 Mb file in less than one second.
16
- - [x] Built-in rules for common validations.
17
- - [x] Configurable severity levels for each rule.
18
- - [x] Human-readable error messages with codeframes and stylish format options.
19
- - [x] Intuitive suggestions for misspelled types or references.
20
- - [x] Easy to implement custom rules.
21
- - [x] Bundle a multifile definition into a single file.
22
- - [x] Decorators to modify a validated definition during bundling.
23
- - [x] Preview reference docs for local development.
24
- - [x] Support for OpenAPI 2 (fka Swagger) and OpenAPI 3.0.
25
- - [ ] Support for OpenAPI 3.1 ([coming soon](https://github.com/Redocly/redocly-cli/issues/160)).
15
+ ```
16
+ npx @redocly/cli lint path-to-root-file.yaml
17
+ ```
26
18
 
27
- ## What makes this tool different
19
+ Alternatively, install it globally with `npm`:
28
20
 
29
- Unlike other OpenAPI linters, `@redocly/cli` defines the possible type tree of a valid OpenAPI definition and then traverses it. This approach is very similar to how linters for programming languages work and results in major performance benefits over other approaches. Extend functionality at different points in the lifecycle with preprocessors, rules, and decorators.
21
+ ```
22
+ npm install @redocly/cli -g
23
+ ```
30
24
 
31
- ## TLDR
25
+ Then you can use it as `redocly [command] [options]`, for example:
32
26
 
33
- `npx @redocly/cli lint path-to-root-file.yaml`
27
+ ```
28
+ redocly lint path-to-root-file.yaml
29
+ ```
34
30
 
35
- ## [Read the docs](https://redoc.ly/docs/cli/)
31
+ ### Docker
32
+
33
+ To give the Docker container access to the OpenAPI definition files, you need to
34
+ mount the containing directory as a volume. Assuming the OAS definition is rooted
35
+ in the current working directory, you need the following command:
36
+
37
+ ```
38
+ docker run --rm -v $PWD:/spec redocly/cli lint path-to-root-file.yaml
39
+ ```
40
+
41
+ To build and run with a local image, run the following from the project root:
42
+
43
+ ```
44
+ docker build -t redocly/cli .
45
+ docker run --rm -v $PWD:/spec redocly/cli lint path-to-root-file.yaml
46
+ ```
47
+
48
+ ## Common tasks
49
+
50
+ ### Generate API reference documentation
51
+
52
+ Redocly CLI is a great way to render API reference documentation. It uses open source [Redoc](https://github.com/redocly/redoc) to build your documentation. Use a command like this:
53
+
54
+ ```
55
+ redocly build-docs openapi.yaml
56
+ ```
57
+
58
+ Your API reference docs are in `redoc-static.html` by default. You can customize this in many ways. [Read the main docs](https://redocly.com/docs/cli/commands/build-docs) for more information.
59
+
60
+ > :bulb: Redocly also has [hosted API reference docs](https://redocly.com/docs/api-registry/guides/api-registry-quickstart/), a (commercial) alternative to Redoc. Both Redoc and Redocly API reference docs can be worked on locally using the `preview-docs` command.
61
+
62
+ ### Lint an API description against a standard
63
+
64
+ Check your API meets the expected standards using `lint` to ensure quality in every version of your API. Our API linter is designed for speed on even large documents, so it's easy to run locally, in CI, or anywhere you need it. It's also designed for humans, with meaningful error messages to help you get your API right every time. Try it like this:
65
+
66
+ ```
67
+ redocly lint openapi.yaml
68
+ ```
69
+
70
+ **Configure the rules** as you wish. No JSONPath here, just type-aware expressions that understand the OpenAPI structure. You can either use the [built-in rules](https://redocly.com/docs/cli/rules) to mix-and-match your ideal API standard, or break out the tools to build your own.
71
+
72
+ **Format the output** in whatever way you need, the `stylish` output is as good as it sounds, but if you need JSON or Checkstyle outputs to integrate with other tools, we've got those too.
73
+
74
+ **Multiple files supported** so you don't need to bundle your API description to lint it, just give the entry point and Redocly CLI does the rest.
75
+
76
+ [Learn more about API standards and configuring Redocly rules](https://redocly.com/docs/cli/api-standards).
77
+
78
+ ### Transform an OpenAPI description
79
+
80
+ If your OpenAPI description isn't everything you hoped it would be, enhance it with the Redocly [decorators](https://redocly.com/docs/cli/decorators) feature. This allows you to:
81
+
82
+ - Publish reference docs with a subset of endpoints for public use
83
+ - Improve the docs by adding examples and descriptions
84
+ - Adapt an existing OpenAPI description, and replace details like URLs for use on staging platforms
85
+
86
+ ## Data collection
87
+
88
+ This tool [collects data](./docs/usage-data.md) to help Redocly improve our products and services. You can opt out by setting the `REDOCLY_TELEMETRY` environment variable to `off`.
89
+
90
+ ## More resources
91
+
92
+ [Read the detailed docs](https://redocly.com/docs/cli/).
36
93
 
37
94
  ## Credits
38
95
 
39
- Thanks to [graphql-js](https://github.com/graphql/graphql-js) and [eslint](https://github.com/eslint/eslint) for inspiration of the definition traversal approach and to [Swagger](https://github.com/swagger-api/swagger-editor), [Spectral](https://github.com/stoplightio/spectral), and [OAS-Kit](https://github.com/Mermade/oas-kit) for inspiring the ruleset.
96
+ Thanks to [graphql-js](https://github.com/graphql/graphql-js) and [eslint](https://github.com/eslint/eslint) for inspiration of the definition traversal approach and to [Swagger](https://github.com/swagger-api/swagger-editor), [Spectral](https://github.com/stoplightio/spectral), and [OAS-Kit](https://github.com/Mermade/oas-kit) for inspiring the recommended ruleset.
97
+
98
+ ## Development
99
+
100
+ Contributions are welcome! All the information you need is in [CONTRIBUTING.md](.github/CONTRIBUTING.md).
package/bin/cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require("../lib/index");
3
+ require('../lib/index');
@@ -1,4 +1,5 @@
1
1
  /// <reference types="jest" />
2
+ import { Document } from '@redocly/openapi-core';
2
3
  export declare const __redoclyClient: {
3
4
  isAuthorizedWithRedocly: jest.Mock<any, any>;
4
5
  isAuthorizedWithRedoclyByRegion: jest.Mock<any, any>;
@@ -23,10 +24,23 @@ export declare const RedoclyClient: jest.Mock<{
23
24
  }, []>;
24
25
  export declare const loadConfig: jest.Mock<{
25
26
  configFile: null;
26
- lint: {
27
+ styleguide: {
28
+ addIgnore: jest.Mock<any, any>;
27
29
  skipRules: jest.Mock<any, any>;
28
30
  skipPreprocessors: jest.Mock<any, any>;
31
+ saveIgnore: jest.Mock<any, any>;
29
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
+ };
30
44
  };
31
45
  }, []>;
32
46
  export declare const getMergedConfig: jest.Mock<any, any>;
@@ -42,3 +56,41 @@ export declare const getTotals: jest.Mock<{
42
56
  }, []>;
43
57
  export declare const formatProblems: jest.Mock<any, any>;
44
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
+ }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.slash = exports.formatProblems = exports.getTotals = exports.bundle = exports.lint = exports.getMergedConfig = exports.loadConfig = exports.RedoclyClient = exports.__redoclyClient = void 0;
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");
4
6
  exports.__redoclyClient = {
5
7
  isAuthorizedWithRedocly: jest.fn().mockResolvedValue(true),
6
8
  isAuthorizedWithRedoclyByRegion: jest.fn().mockResolvedValue(true),
@@ -16,13 +18,62 @@ exports.__redoclyClient = {
16
18
  },
17
19
  };
18
20
  exports.RedoclyClient = jest.fn(() => exports.__redoclyClient);
19
- exports.loadConfig = jest.fn(() => ({
20
- configFile: null,
21
- lint: { skipRules: jest.fn(), skipPreprocessors: jest.fn(), skipDecorators: jest.fn() },
22
- }));
21
+ exports.loadConfig = jest.fn(() => config_1.ConfigFixture);
23
22
  exports.getMergedConfig = jest.fn();
24
23
  exports.lint = jest.fn();
25
24
  exports.bundle = jest.fn(() => ({ bundle: { parsed: null }, problems: null }));
26
25
  exports.getTotals = jest.fn(() => ({ errors: 0 }));
27
26
  exports.formatProblems = jest.fn();
28
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
+ };
@@ -5,3 +5,5 @@ export declare const statSync: jest.Mock<{
5
5
  size: number;
6
6
  }, []>;
7
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>;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createReadStream = exports.statSync = exports.readFileSync = exports.existsSync = void 0;
3
+ exports.mkdirSync = exports.writeFileSync = exports.createReadStream = exports.statSync = exports.readFileSync = exports.existsSync = void 0;
4
4
  exports.existsSync = jest.fn();
5
5
  exports.readFileSync = jest.fn(() => '');
6
6
  exports.statSync = jest.fn(() => ({ size: 0 }));
7
7
  exports.createReadStream = jest.fn();
8
+ exports.writeFileSync = jest.fn();
9
+ exports.mkdirSync = jest.fn();
@@ -0,0 +1,4 @@
1
+ /// <reference types="jest" />
2
+ export declare const performance: {
3
+ now: jest.Mock<any, any>;
4
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.performance = void 0;
4
+ exports.performance = {
5
+ now: jest.fn(),
6
+ };
@@ -0,0 +1,7 @@
1
+ /// <reference types="jest" />
2
+ export declare const loadAndBundleSpec: jest.Mock<Promise<{
3
+ openapi: string;
4
+ }>, []>;
5
+ export declare const createStore: jest.Mock<Promise<{
6
+ toJS: jest.Mock<string, []>;
7
+ }>, []>;
@@ -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(() => '{}') }));
@@ -1,8 +1,5 @@
1
1
  /// <reference types="jest" />
2
- export declare const getFallbackEntryPointsOrExit: jest.Mock<any, [entrypoints: any]>;
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]>;
@@ -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.getTotals = exports.getFallbackEntryPointsOrExit = void 0;
4
- exports.getFallbackEntryPointsOrExit = jest.fn((entrypoints) => entrypoints.map(() => ({ path: '' })));
5
- exports.getTotals = jest.fn(() => ({ errors: 0 }));
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
+ });