@redocly/cli 1.34.4 → 2.0.0-next.0

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